# Dataset Deduplicator & Merger: Merge, Dedupe CSV/JSON (`datagleaner/dataset-dedup-merge`) Actor

Merge several Apify datasets and CSV/JSON files into one, remove duplicate items on the fields you choose, with trim, lowercase and URL/email normalization. Streams in pages, so 1M+ items work. $0.0002 per 1,000 input items.

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

## Pricing

$0.20 / 1,000 1,000 input items processeds

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 Deduplicator & Merger: merge Apify datasets and CSV/JSON files, remove duplicates

**Merge several Apify datasets, CSV files and JSON files into one dataset and drop duplicate items on the fields you choose.** Compare values after normalization (trim, lowercase, strip `https://www.` and trailing slashes, lowercase emails), keep the first or the last copy, and tag every item with the source it came from. It reads in pages and keeps only a small fingerprint per distinct item, so inputs of a million items and more run in 512 MB instead of running out of memory.

It only processes data you point it at: your own datasets (or ones shared with your account) and file URLs you give it. It does not scrape any website.

### What it is for

- **Combine the output of repeated scraper runs** (daily Google Maps, jobs or product runs) into one list without the same business or listing twice.
- **Merge lead lists** from several Actors or CSV exports and keep one row per email, domain or phone number.
- **Clean a CSV or JSON export** before importing it into a CRM or database: `Ada@Example.com` and `ada@example.com` become one contact.
- **Build a master dataset** from many runs, with a `_sourceDataset` field that tells you where each kept item first appeared.

### How it works

1. You give it dataset IDs and/or file URLs (any mix, any number). Sources are read one after another in the order given.
2. For each item it builds a key from the `dedupeFields` you choose (or the whole item when the list is empty) after the normalization you select.
3. The first copy of each key is kept (or the last, with `keep: last`); later copies are dropped. Items with no value in the dedupe fields cannot be judged duplicates and are kept unless you turn `dropItemsWithoutKey` on.
4. Kept items are written unchanged to this run's default dataset, in batches. Normalization is used for comparing only; your values are never rewritten.

Memory use is about 100 bytes per distinct item, not per item size, which is why large inputs work. `keep: last` reads your sources twice, but you are billed for one read.

### Input example

```json
{
  "datasetIds": ["WkzbQMuFYuamGv3YF", "x9F3tDgR2uKq1mLpA"],
  "urls": ["https://example.com/export/contacts.csv"],
  "dedupeFields": ["email"],
  "normalize": ["trim", "emailLowercase"],
  "keep": "first",
  "includeSourceDataset": true
}
```

Leave every source empty to run a built-in 8-contact example (dedupes on email, 5 items come out). Fields:

| Field | What it does |
| --- | --- |
| `datasetId` / `datasetIds` | Datasets to read (IDs or `username~name`). Must be on your account or shared with it. |
| `urls` | http(s) links to CSV, JSON (array of objects) or JSON Lines files. Up to 500 MB (JSON arrays up to 150 MB; use JSON Lines for bigger). |
| `dedupeFields` | Fields that define a duplicate; dotted paths like `contact.email` work. Empty means the whole item. |
| `normalize` | `trim`, `collapseWhitespace`, `emailLowercase`, `stripUrl`, `lowercase`. |
| `keep` | `first` (default) or `last`. |
| `dropItemsWithoutKey` | Drop items whose dedupe fields are all empty (default: keep them). |
| `includeSourceDataset` | Add `_sourceDataset` to each item (default on). |
| `maxItems` | Stop after this many input items (default 5,000,000). |

CSV files are read with the delimiter found in the header (comma, semicolon, tab or pipe); every CSV value is a string, so `1` and `01` differ unless you compare on a text field.

### Output example

```json
{
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "website": "https://www.example.com/",
  "_sourceDataset": "WkzbQMuFYuamGv3YF"
}
```

The run's status message summarizes the result, for example: `Read 120,000 items from 3 source(s), kept 97,412, removed 22,588 duplicates (keep first). Billed 120 x 1,000-item event(s).` When nothing can be output (bad dataset ID, unreadable URL), one free notice row says why and the run still ends successfully.

### Pricing

**$0.0002 per 1,000 input items read** (pay per event), counted on items read from your sources, whether they are kept or removed as duplicates, rounded up per run. Output rows are not charged. Unreadable sources and notice rows are free. Examples: 10,000 items cost $0.002; 1,000,000 items cost $0.20. Platform usage for the run is included in this price. Set a maximum charge on the run and the Actor stops reading at it, ending successfully with the items processed so far.

### Why runs finish

Merge and dedupe jobs fail when they load everything into memory, when one unreadable source stops the whole run, or when the account cannot read the dataset. This Actor is built around those three:

- **Paged reads and fingerprints, not whole datasets in memory**, so size is limited by the number of distinct items, not their size.
- **A source it cannot read does not fail the run.** It is skipped, named in the status message, and the other sources are still merged.
- **Clear permission handling.** The dataset picker declares read access to the dataset you choose. If a dataset ID cannot be read, the status message says it was not found or is not shared with this run.
- **Time limits end the run with output, not a timeout.** It stops reading about 30 seconds before the run's time limit, writes what it has and says so.
- **Restart safe.** If Apify moves the run to another machine, it does not write or bill the same items twice.

### Limits

- Items are compared exactly after normalization; there is no fuzzy matching, so `Acme Inc` and `Acme Incorporated` stay separate unless you compare on another field such as the domain.
- `keep: last` and `keep: first` follow the order of the sources and the order of items inside each. Dataset order is the order they were pushed.
- Memory: about 100 bytes per distinct item, so 512 MB covers a few million distinct items; raise the run memory above that.
- Non-object JSON values (numbers, strings) are wrapped as `{"value": ...}`.
- URLs on localhost or private networks are refused.

### FAQ

**Does it change my original datasets?** No. It reads them and writes a new dataset in this run.

**Can I dedupe one dataset against another without merging?** Give both IDs and the same dedupe fields; the first dataset's items win, the second dataset's duplicates are dropped.

**Which URL forms work?** Any public http(s) link to a CSV, JSON or JSON Lines file, such as a file in a key-value store or cloud bucket, or a link from a data export. Only fetch files you have the right to process.

**What does an empty input do?** It runs the built-in example, says so in the status message, and succeeds with 5 items.

### Responsible use

This Actor processes only the datasets and files you give it. If they contain personal data, such as names or emails, your own obligations under data-protection law (a lawful basis, retention, and honouring opt-outs) apply to what you do with the merged output; the Actor stores nothing beyond the run's output dataset, which you control. Only merge data you are allowed to use.

# Actor input Schema

## `datasetId` (type: `string`):

Optional. Pick one of your datasets here. Use the list below to merge several. Leave every source empty to run a built-in 8-contact example.

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

Dataset IDs (or `username~dataset-name`), one per line. They are read in this order, so with Keep first the earlier dataset wins a tie. Datasets must be on your own account or shared with it. Leave every source empty to run a built-in 8-contact example.

## `urls` (type: `array`):

Public http(s) links to CSV, JSON (array of objects) or JSON Lines files, for example a file in your own key-value store or storage bucket. Files up to 500 MB (a JSON array up to 150 MB; use JSON Lines for bigger). Only files you have the right to process.

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

Two items are duplicates when all of these fields are equal after normalization. Dotted paths work (`contact.email`). Empty means the whole item must be equal.

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

Keep the first or the last copy of each duplicate. Output order follows the sources.

## `normalize` (type: `array`):

Applied to the values being compared only; your items are output unchanged. Default when omitted: trim.

## `dropItemsWithoutKey` (type: `boolean`):

Items whose dedupe fields are all missing or empty cannot be judged duplicates. Off (default): keep them. On: drop them.

## `includeSourceDataset` (type: `boolean`):

Adds a `_sourceDataset` field with the dataset id or file URL each kept item came from.

## `maxItems` (type: `integer`):

Stop reading after this many input items. You pay per 1,000 input items read. Memory use is about 100 bytes per distinct item, so keep 512 MB for up to 3 million and raise the run memory beyond that.

## Actor input object example

```json
{
  "datasetIds": [
    "WkzbQMuFYuamGv3YF",
    "x9F3tDgR2uKq1mLpA"
  ],
  "urls": [
    "https://example.com/export/contacts.csv"
  ],
  "dedupeFields": [
    "url"
  ],
  "keep": "first",
  "normalize": [
    "trim",
    "emailLowercase"
  ],
  "dropItemsWithoutKey": false,
  "includeSourceDataset": true,
  "maxItems": 100000
}
```

# Actor output Schema

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

No description

# 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 = {
    "dedupeFields": [
        "email"
    ],
    "normalize": [
        "trim",
        "emailLowercase"
    ],
    "maxItems": 100000
};

// Run the Actor and wait for it to finish
const run = await client.actor("datagleaner/dataset-dedup-merge").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 = {
    "dedupeFields": ["email"],
    "normalize": [
        "trim",
        "emailLowercase",
    ],
    "maxItems": 100000,
}

# Run the Actor and wait for it to finish
run = client.actor("datagleaner/dataset-dedup-merge").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 '{
  "dedupeFields": [
    "email"
  ],
  "normalize": [
    "trim",
    "emailLowercase"
  ],
  "maxItems": 100000
}' |
apify call datagleaner/dataset-dedup-merge --silent --output-dataset

```

## MCP server setup

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

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/8EtOA9nsyXDuAbzzz/builds/vZkuMp0amd0ycuoaL/openapi.json
