# Merge & Dedup Datasets: Combine Runs, Remove Duplicates (`keel-data/dataset-merge-dedup`) Actor

Merge Apify datasets and JSON, JSON Lines or CSV files into one clean dataset and remove duplicate rows by any fields (nested too), case- and space-insensitive. Keep the first or last copy, or list only the duplicates. Pay only per row delivered.

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

## Pricing

from $0.07 / 1,000 rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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 & Dedup Datasets: Combine Runs, Remove Duplicates

Merge the results of **several scraper runs** (or JSON and CSV files) into **one clean dataset** and **remove duplicate rows**. Choose the fields that make a row unique, such as `url` or `name` + `address`, and keep the first or the newest copy.

**You pay only per row delivered.** Duplicates removed, empty rows and sources that can't be read are free.

### Why this one

- **Works with limited permissions.** Pick your datasets with the dataset picker and the run can read them. You don't need to grant full account access, and runs don't fail on permissions.
- **Smart matching.** `"ACME Inc "` and `"acme inc"` count as the same by default. Nested fields (`location.city`), arrays and objects are compared by value.
- **Keep first or last.** "Last" keeps the newest copy, which helps when later runs have fresher prices or ratings.
- **Check before you delete.** The "Only the duplicates" output shows exactly what would be removed.
- **Files too.** Public JSON, JSON Lines, CSV and TSV links (up to 300 MB each) are merged together with your datasets.
- **Big datasets.** Reads in pages and stores only a short fingerprint per row, so millions of rows fit in normal memory. If Apify moves the run to another server, it carries on where it stopped and never charges a row twice.
- **No code needed.** Keep or drop fields with simple lists instead of JavaScript functions.

### How to use it

1. Pick one or more **datasets** (for example the last 7 runs of a scraper) and/or paste **file URLs**.
2. Under **Fields that make a row unique**, enter field names such as `url`. Leave the list empty to remove only rows that are identical in every field.
3. Choose **First copy** or **Last copy**, then run. Download the result as JSON, CSV or Excel, or send it on to Google Sheets, Make, Zapier or n8n.

#### Example input

```json
{
  "datasetIds": ["aBcDeFgHiJkLmNoPq", "QrStUvWxYzAbCdEfG"],
  "dedupFields": ["placeId"],
  "keep": "last",
  "fieldsToOmit": ["html", "debug"],
  "addSource": true
}
```

#### Example output

Your own rows, unchanged apart from the fields you keep or remove. With **Add the source** switched on, each row also gets `_source` (the dataset ID or file URL it came from).

The **Run stats** record (`RUN_STATS`) shows, for each source, how many rows were read and kept, how many were duplicates, how many had empty key fields, and any read errors.

### Options

| Option | What it does |
|---|---|
| Datasets to merge | Datasets from your account, merged in this order. IDs, names and dataset URLs also work. |
| Files to merge | Public JSON / JSON Lines / CSV / TSV links, merged after the datasets. |
| Remove duplicates | Turn off to only merge. |
| Fields that make a row unique | One or more fields; dots for nested fields. Empty = whole-row comparison. |
| Which copy to keep | First (earliest source) or last (newest). |
| Output | Unique rows, or only the duplicates. |
| Ignore case / extra spaces | On by default. |
| Rows with an empty key field | Keep them all, drop them, or compare them like other rows. |
| Keep only / remove these fields | Shape the output without code. |
| Max rows read per source / delivered | Limits for testing or sampling. |

### Pricing

Pay per event: one **row** event per row delivered. No start fee and no extra platform-usage charge. You can set a maximum cost per run; the Actor stops cleanly when it's reached.

### Notes

- Only datasets your account can access can be read. The Actor never changes or deletes your source datasets.
- Not affiliated with any of the websites your data comes from.

Made by Keel Data: data tools that don't break.

# Actor input Schema

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

Pick datasets from your account (for example the results of several scraper runs). They are merged in this order. You can also paste dataset IDs, names or dataset URLs.

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

Public links to JSON, JSON Lines or CSV/TSV files (up to 300 MB each), for example an exported dataset or a CSV from another tool. Merged after the datasets.

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

Turn off to only merge the sources.

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

Rows with the same values in all these fields are duplicates, e.g. url, or name + address. Nested fields use dots: location.city. Leave empty to remove only rows that are identical in every field.

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

First = the copy from the earliest source. Last = the newest copy (useful when later runs have fresher data).

## `output` (type: `string`):

Unique rows (the clean, merged dataset) or only the duplicates that would be removed (to check your data).

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

"ACME Inc" and "acme inc" count as the same.

## `trimWhitespace` (type: `boolean`):

Leading, trailing and repeated spaces are ignored when comparing.

## `missingKeys` (type: `string`):

What to do with rows where one of the fields above is missing or empty.

## `fieldsToKeep` (type: `array`):

Output only these fields (dots for nested fields). Leave empty to keep every field.

## `fieldsToOmit` (type: `array`):

Drop these fields from the output, e.g. large HTML or debug fields.

## `addSource` (type: `boolean`):

Adds a \_source field with the dataset ID or file URL the row came from.

## `maxItemsPerSource` (type: `integer`):

Read at most this many rows from each dataset or file. 0 = all.

## `maxOutputItems` (type: `integer`):

Stop after delivering this many rows. 0 = no limit.

## Actor input object example

```json
{
  "fileUrls": [],
  "deduplicate": true,
  "dedupFields": [],
  "keep": "first",
  "output": "unique",
  "ignoreCase": true,
  "trimWhitespace": true,
  "missingKeys": "keep",
  "fieldsToKeep": [],
  "fieldsToOmit": [],
  "addSource": false,
  "maxItemsPerSource": 0,
  "maxOutputItems": 0
}
```

# Actor output Schema

## `rows` (type: `string`):

The merged rows with duplicates removed (or only the duplicates, if you chose that output).

## `runStats` (type: `string`):

Per source: rows read, kept, duplicates, rows with empty key fields and read errors.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("keel-data/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 = {}

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

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,keel-data/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/SMkv298oMhmhB7uBP/builds/G3SBhHmImMG2ghTuT/openapi.json
