# Dataset Merge & Deduplicate (Apify datasets, CSV, JSON) (`klyve1/dataset-merge-deduplicate`) Actor

Merge several Apify datasets, CSV or JSON files into one clean dataset and remove duplicates by any fields, with normalisation, keep first, last or most complete, merging of missing values and an only-new-items mode across runs.

- **URL**: https://apify.com/klyve1/dataset-merge-deduplicate.md
- **Developed by:** [Nico Klyve](https://apify.com/klyve1) (community)
- **Categories:** Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 1,000 output rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Dataset Merge & Deduplicate (Apify datasets, CSV, JSON)

Merge the results of **several scraper runs, Apify datasets, CSV or JSON files** into one clean dataset and **remove duplicates** by the fields you choose. Values are normalised before comparing (case, spaces, http/https, www, trailing slash), you decide which copy to keep, missing values can be filled from the other copies, and an **only-new-items** mode remembers what was already output so a scheduled run returns only fresh results.

### Who uses it

- **Lead generation**: merge Google Maps, directory and website scrapes, keep one row per website or email, with the phone found in any copy.
- **Scheduled scrapers**: run after each daily scrape and get only the items that were never seen before (new listings, new articles, new products).
- **Data teams**: join exports from several tools into one CSV without double counting.
- **Integrations (Make, Zapier, n8n)**: send only new, unique rows to a CRM or a spreadsheet.

### Example

Input rows (from the prefill):

```json
[
  { "company": "Acme Corp", "website": "https://www.acme.com/", "city": "Paris", "phone": "" },
  { "company": "ACME corp ", "website": "http://acme.com", "city": "", "phone": "+33 1 23 45 67 89" },
  { "company": "Globex", "website": "https://globex.example", "city": "Lyon", "phone": "+33 4 00 00 00 00" },
  { "company": "Initech", "website": "https://initech.example", "city": "Nantes", "phone": "" },
  { "company": "Globex", "website": "https://globex.example/", "city": "Lyon", "phone": "+33 4 00 00 00 00" }
]
```

Output with `dedupeFields: ["website"]`, `fillMissingValues` and `addDuplicateCount`:

```json
[
  { "company": "Acme Corp", "website": "https://www.acme.com/", "city": "Paris", "phone": "+33 1 23 45 67 89", "_duplicateCount": 2 },
  { "company": "Globex", "website": "https://globex.example", "city": "Lyon", "phone": "+33 4 00 00 00 00", "_duplicateCount": 2 },
  { "company": "Initech", "website": "https://initech.example", "city": "Nantes", "phone": "", "_duplicateCount": 1 }
]
```

A `SUMMARY` record in the run's key-value store gives the counts: input rows per source, unique rows, duplicates removed, items already seen in previous runs and output rows.

### Input

| Field | What it does | Default |
|---|---|---|
| `datasetIds` | Apify datasets to merge, read in order (read access only) | empty |
| `dataUrls` | CSV, JSON or JSONL file links (comma, semicolon or tab CSV) | empty |
| `jsonData` | Rows pasted as a JSON array | empty |
| `dedupeFields` | Fields that identify a duplicate (`url`, `email`, or `name` + `city`...); dots reach nested fields. Empty = whole row | whole row |
| `normalize` | Ignore case, spaces, http/https, www and trailing slashes when comparing | true |
| `keep` | `first`, `last` or `mostComplete` (most filled fields) | first |
| `fillMissingValues` | Fill empty fields of the kept row from its duplicates | false |
| `onlyNewItems` | Skip items already output by earlier runs (history in a named key-value store) | false |
| `historyStoreName` | Name of that history store, one per use case | klyve1-dataset-dedupe-history |
| `addSourceField` | Add `_source` (dataset ID or URL of each row) | false |
| `addDuplicateCount` | Add `_duplicateCount` | false |
| `maxInputRows` | Cap on rows read (0 = no limit) | 0 |

Give at least one dataset, URL or JSON data.

### Pricing

Pay per result: **$0.002 per 1,000 output rows** (each started block of 1,000 counts). Duplicates removed and items skipped as already seen are free.

### Good to know

- Rows whose dedupe fields are all empty are never merged together: they are all kept.
- The output keeps the original values: normalisation is only used to compare.
- In only-new mode the history is saved at the end of a successful run. Use a different `historyStoreName` for each scraper or list, and the same one between runs of the same list.
- Everything runs in memory: up to a few hundred thousand rows per run works with the default memory.

# Actor input Schema

## `datasetIds` (type: `array`):

Apify datasets to merge, for example the default datasets of several scraper runs (pick them, or give their IDs through the API). They are read in this order. Only read access is requested.

## `dataUrls` (type: `array`):

Optional links to CSV, JSON or JSONL files (up to 200 MB each), for example exports or Apify dataset item URLs. Comma, semicolon and tab separated CSV are detected.

## `jsonData` (type: `array`):

Optional rows pasted directly as a JSON array of objects.

## `dedupeFields` (type: `array`):

Fields that identify a duplicate, for example url, or email, or name and city together. Dots reach nested fields (address.city). Empty = two rows are duplicates only when the whole row is the same.

## `normalize` (type: `boolean`):

Ignore case, extra spaces, http/https, www and trailing slashes when comparing, so Acme.com/ and https://www.acme.com match. The output keeps the original values.

## `keep` (type: `string`):

first = the first row met (sources are read in order). last = the last one. mostComplete = the row with the most filled fields.

## `fillMissingValues` (type: `boolean`):

Complete empty fields of the kept row with values found in its duplicates (for example a phone number present only in the second copy).

## `onlyNewItems` (type: `boolean`):

Remember the keys of the items output by this Actor in a named key-value store, and skip them in the next runs. Ideal for scheduled scrapers: get only the new results each day.

## `historyStoreName` (type: `string`):

Name of the key-value store that keeps the history for only-new mode. Use one name per use case. Default: klyve1-dataset-dedupe-history.

## `addSourceField` (type: `boolean`):

Add a \_source field with the dataset ID or URL each row came from.

## `addDuplicateCount` (type: `boolean`):

Add a \_duplicateCount field with how many input rows were merged into each output row.

## `maxInputRows` (type: `integer`):

Optional cap on the number of rows read across all sources (0 = no limit).

## Actor input object example

```json
{
  "jsonData": [
    {
      "company": "Acme Corp",
      "website": "https://www.acme.com/",
      "city": "Paris",
      "phone": ""
    },
    {
      "company": "ACME corp ",
      "website": "http://acme.com",
      "city": "",
      "phone": "+33 1 23 45 67 89"
    },
    {
      "company": "Globex",
      "website": "https://globex.example",
      "city": "Lyon",
      "phone": "+33 4 00 00 00 00"
    },
    {
      "company": "Initech",
      "website": "https://initech.example",
      "city": "Nantes",
      "phone": ""
    },
    {
      "company": "Globex",
      "website": "https://globex.example/",
      "city": "Lyon",
      "phone": "+33 4 00 00 00 00"
    }
  ],
  "dedupeFields": [
    "website"
  ],
  "normalize": true,
  "keep": "first",
  "fillMissingValues": true,
  "onlyNewItems": false,
  "addSourceField": false,
  "addDuplicateCount": true,
  "maxInputRows": 0
}
```

# Actor output Schema

## `results` (type: `string`):

All rows produced by the run.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "jsonData": [
        {
            "company": "Acme Corp",
            "website": "https://www.acme.com/",
            "city": "Paris",
            "phone": ""
        },
        {
            "company": "ACME corp ",
            "website": "http://acme.com",
            "city": "",
            "phone": "+33 1 23 45 67 89"
        },
        {
            "company": "Globex",
            "website": "https://globex.example",
            "city": "Lyon",
            "phone": "+33 4 00 00 00 00"
        },
        {
            "company": "Initech",
            "website": "https://initech.example",
            "city": "Nantes",
            "phone": ""
        },
        {
            "company": "Globex",
            "website": "https://globex.example/",
            "city": "Lyon",
            "phone": "+33 4 00 00 00 00"
        }
    ],
    "dedupeFields": [
        "website"
    ],
    "fillMissingValues": true,
    "addDuplicateCount": true
};

// Run the Actor and wait for it to finish
const run = await client.actor("klyve1/dataset-merge-deduplicate").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "jsonData": [
        {
            "company": "Acme Corp",
            "website": "https://www.acme.com/",
            "city": "Paris",
            "phone": "",
        },
        {
            "company": "ACME corp ",
            "website": "http://acme.com",
            "city": "",
            "phone": "+33 1 23 45 67 89",
        },
        {
            "company": "Globex",
            "website": "https://globex.example",
            "city": "Lyon",
            "phone": "+33 4 00 00 00 00",
        },
        {
            "company": "Initech",
            "website": "https://initech.example",
            "city": "Nantes",
            "phone": "",
        },
        {
            "company": "Globex",
            "website": "https://globex.example/",
            "city": "Lyon",
            "phone": "+33 4 00 00 00 00",
        },
    ],
    "dedupeFields": ["website"],
    "fillMissingValues": True,
    "addDuplicateCount": True,
}

# Run the Actor and wait for it to finish
run = client.actor("klyve1/dataset-merge-deduplicate").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "jsonData": [
    {
      "company": "Acme Corp",
      "website": "https://www.acme.com/",
      "city": "Paris",
      "phone": ""
    },
    {
      "company": "ACME corp ",
      "website": "http://acme.com",
      "city": "",
      "phone": "+33 1 23 45 67 89"
    },
    {
      "company": "Globex",
      "website": "https://globex.example",
      "city": "Lyon",
      "phone": "+33 4 00 00 00 00"
    },
    {
      "company": "Initech",
      "website": "https://initech.example",
      "city": "Nantes",
      "phone": ""
    },
    {
      "company": "Globex",
      "website": "https://globex.example/",
      "city": "Lyon",
      "phone": "+33 4 00 00 00 00"
    }
  ],
  "dedupeFields": [
    "website"
  ],
  "fillMissingValues": true,
  "addDuplicateCount": true
}' |
apify call klyve1/dataset-merge-deduplicate --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,klyve1/dataset-merge-deduplicate"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/mpoKwu12iKHgsmxDN/builds/PdRUsgmdiSMENWwmS/openapi.json
