# Merge & Deduplicate Datasets — Apify Datasets, CSV & JSON Files (`openregistry/dataset-merge-dedup`) Actor

Merge several Apify datasets and CSV/JSON/JSONL files into one clean dataset: remove duplicates on any fields (case, spaces, accents, URL normalization), filter rows, pick, drop and rename fields. Duplicates and filtered rows are free. Pay per output row.

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

## Pricing

$0.30 / 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

## Merge & Deduplicate Datasets — Apify Datasets, CSV & JSON Files

Ran the same scraper on ten search queries and got overlapping results? Collected leads from several sources? This Actor **merges any number of Apify datasets and CSV/JSON files into one clean dataset**, removes duplicates on the fields you choose, filters rows and reshapes columns, in one run. **Duplicates and filtered rows are free**: you only pay for the rows you get.

### Features

- **Sources**: Apify datasets (pick them or paste IDs), plus public links to CSV, TSV, JSON or JSONL files (Google Sheets CSV export, S3, GitHub raw...). CSV delimiter, BOM and Windows-1252 encoding detected automatically.
- **Deduplication on any fields**, including nested ones (`address.city`), or on whole rows. Smart comparison: ignore case, extra spaces, accents, and `http/https`, `www.` and trailing slashes in URLs.
- **Keep the first or the last** occurrence (oldest or newest data wins).
- **Filters**: equals, contains, starts/ends with, greater/less than (numbers and dates), exists, empty, regex. All filters must match.
- **Reshape**: keep only some fields (in your order, flattening nested values), drop fields, rename fields.
- **Traceability**: optional `_source` column, and a per-source summary (rows read, duplicates, filtered, errors) saved as `SUMMARY`.

### What it is for

- **Combine scraper runs**: Google Maps, LinkedIn, e-commerce or job scrapers run per keyword or city, then one deduplicated list.
- **Lead lists**: merge exports from several tools and remove duplicate emails, phones or domains.
- **Incremental pipelines**: merge yesterday's and today's data and keep the newest version of each item.
- **Clean before export**: filter and rename columns before sending to Google Sheets, a CRM or a database.
- **Automation**: chain it after other Actors with Apify integrations, Make, Zapier or n8n.

### Input example

```json
{
  "datasetIds": ["<dataset-id-1>", "<dataset-id-2>"],
  "fileUrls": ["https://example.com/exports/leads.csv"],
  "dedupFields": ["email"],
  "ignoreCase": true,
  "filters": [{ "field": "rating", "operator": "gte", "value": 4 }],
  "fields": ["name", "email", "address.city", "rating"],
  "renameFields": { "address.city": "city" },
  "addSourceField": true
}
```

- `datasetIds`, `fileUrls` — sources, read in this order.
- `dedupFields`, `ignoreCase`, `normalizeWhitespace`, `ignoreAccents`, `normalizeUrls`, `skipEmptyKeys`, `keepDuplicate` — duplicate detection.
- `filters` — `{ field, operator, value }` objects.
- `fields`, `omitFields`, `renameFields`, `addSourceField` — output shape.
- `maxItems` — stop condition, you control the cost.

### Output example

One row per kept item, with your fields:

```json
{
  "name": "Blue Bottle Coffee",
  "email": "hello@example.com",
  "city": "Oakland",
  "rating": 4.6,
  "_source": "<dataset-id-1>"
}
```

The run's status message gives the totals, e.g. `1201 rows delivered from 1205 read (4 duplicates, 0 filtered out, both free)`.

### Good to know

- Datasets are read with the permissions of the run: your own datasets, and datasets shared with you or with public access. A source that cannot be read is listed with its error in `SUMMARY`; the other sources are still merged.
- File links are fetched with a plain HTTP request identifying the Actor (`OpenRegistry-DatasetMerge`), respecting `robots.txt`.
- CSV values are typed carefully: `true/false` and plain numbers become booleans and numbers, but codes with leading zeros (`01234`) stay text.
- Output rows keep the order of the sources. With `keepDuplicate: "last"`, each row stays at the position where it was first seen, with the newest values.

### Pricing

**$0.0003 per output row** ($0.30 per 1,000 rows). Duplicates and filtered-out rows are free. Set a maximum charge per run in the Apify console and the Actor stops cleanly when it is reached.

# Actor input Schema

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

Datasets to merge, in order (e.g. the default datasets of several scraper runs). Pick them or paste their IDs.

## `fileUrls` (type: `array`):

Optional public links to files (Google Sheets CSV export, S3, GitHub raw, another Actor's export...). Format detected from the extension, the content type or the content. Delimiter auto-detected for CSV.

## `deduplicate` (type: `boolean`):

Turn off to only merge, filter and reshape.

## `dedupFields` (type: `array`):

Rows with the same values in all these fields are duplicates. Dotted paths work for nested fields (address.city). Empty = compare whole rows.

## `ignoreCase` (type: `boolean`):

Jane@X.com = jane@x.com

## `normalizeWhitespace` (type: `boolean`):

Trims and collapses spaces before comparing.

## `ignoreAccents` (type: `boolean`):

Café = Cafe

## `normalizeUrls` (type: `boolean`):

Ignores http/https, www. and a trailing slash when comparing.

## `skipEmptyKeys` (type: `boolean`):

Rows where all key fields are empty are all kept instead of being treated as one duplicate.

## `keepDuplicate` (type: `string`):

"Last seen" keeps rows in memory until the end; give the run more memory above a few million rows.

## `filters` (type: `array`):

Optional. Objects { "field", "operator", "value" }. Operators: equals, notEquals, contains, notContains, startsWith, endsWith (case-insensitive), gt, gte, lt, lte (numbers or dates), exists, notExists, isEmpty, notEmpty, regex.

## `fields` (type: `array`):

Optional, in this order. Dotted paths flatten nested values (address.city).

## `omitFields` (type: `array`):

Optional.

## `renameFields` (type: `object`):

Optional, e.g. { "address.city": "city", "fullName": "name" }.

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

Dataset ID or file URL each row came from.

## `maxFileSizeMb` (type: `integer`):

For file links.

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

Optional. The run stops once this many rows are delivered, so you control the cost.

## Actor input object example

```json
{
  "deduplicate": true,
  "dedupFields": [
    "url"
  ],
  "ignoreCase": true,
  "normalizeWhitespace": true,
  "ignoreAccents": false,
  "normalizeUrls": false,
  "skipEmptyKeys": true,
  "keepDuplicate": "first",
  "addSourceField": false,
  "maxFileSizeMb": 100
}
```

# Actor output Schema

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

No description

## `summary` (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 = {
    "dedupFields": [
        "url"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("openregistry/dataset-merge-dedup").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 = { "dedupFields": ["url"] }

# Run the Actor and wait for it to finish
run = client.actor("openregistry/dataset-merge-dedup").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 '{
  "dedupFields": [
    "url"
  ]
}' |
apify call openregistry/dataset-merge-dedup --silent --output-dataset

```

## MCP server setup

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

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/KKLdbAJ5AeNUiE6Rd/builds/pfePMMdyS7TsjOfZg/openapi.json
