# Merge & Deduplicate Datasets (`dojito/merge-dedup-datasets`) Actor

Merge several Apify datasets into one and remove duplicate rows by the fields you choose (or whole rows), with optional filters and field selection. Runs with limited permissions: pick datasets in the input, API IDs work too.

- **URL**: https://apify.com/dojito/merge-dedup-datasets.md
- **Developed by:** [Dongjin Kim](https://apify.com/dojito) (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 $0.20 / 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.
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 & Deduplicate Datasets** combines several of your Apify datasets into one and **removes duplicate rows** — by the fields you choose (for example `url`, or `name` + `city`) or by the whole row. You can also **filter rows** with simple conditions and **keep only the fields you need**. The result lands in the run's dataset, ready to export as JSON, CSV or Excel.

It runs with **limited permissions**: it can read only the datasets you give it in the **Datasets** field, and nothing else in your account. The picker in Console and dataset IDs (or `username~name`) passed through the API or a saved task fill the same field, and the platform grants read access to exactly those datasets. We tested the API and saved-task paths with limited permissions in the cloud.

### How to use

1. In **Datasets**, pick the datasets to merge (for example the results of several scraper runs). Their order matters: rows of the first dataset come first.
2. In **Deduplicate by fields**, list the field(s) that identify a row — `url` is prefilled. Leave it empty to compare whole rows.
3. Optional: turn on **Ignore letter case** or **Ignore trailing slash in URLs**, choose whether to keep the **first** or **last** duplicate, add a **Filter**, or list **Output fields**.
4. Click **Start**. The summary (rows read, duplicates removed, rows out — per dataset) is in the **OUTPUT** record.

**Just trying it?** Leave **Datasets** empty and click **Start**: the prefilled **Or: rows as JSON** field holds two tiny sample groups (4 rows, one duplicate `url`), and you get 3 rows back. As soon as you pick a dataset, the sample rows are ignored.

**Over the API**, pass dataset IDs (or `username~dataset-name`) as strings:

```json
{
  "datasetIds": ["aBcD1234eFgH5678i", "jKlM9012nOpQ3456r"],
  "dedupFields": ["url"],
  "ignoreTrailingSlash": true,
  "keep": "first"
}
```

Calling it from another Actor or an Apify integration works the same way: put the IDs in `datasetIds`.

### What you get

**The rows themselves, unchanged** (the normalization options only affect how rows are compared). With **Add source dataset ID** each row also gets `_sourceDataset`. With **Output fields** each row has exactly those fields, in that order (`null` when a row lacks one; dots reach nested values, e.g. `address.city`).

The **OUTPUT** record (key-value store) — from a real test run (15,020 rows out of 19,020), abridged:

```json
{
  "rowsOut": 15020, "rowsRead": 19020, "duplicatesRemoved": 4000, "filteredOut": 0, "rowsWithoutKey": 20,
  "datasets": [
    {"dataset": "<id A>", "status": "ok", "rowsRead": 10000, "rowsOut": 10000, "duplicatesRemoved": 0},
    {"dataset": "<id B>", "status": "ok", "rowsRead": 6000, "rowsOut": 3000, "duplicatesRemoved": 3000},
    {"dataset": "dojito~<name C>", "status": "ok", "rowsRead": 3020, "rowsOut": 2020, "duplicatesRemoved": 1000},
    {"dataset": "ZzZzZzZzZzZzZzZzZ", "status": "skipped", "error": "Cannot read dataset 'ZzZzZzZzZzZzZzZzZ' (404). Select it in the 'Datasets' picker, or pass its exact ID ..."}
  ],
  "stoppedEarly": null
}
```

### Input

| Field | What it does |
|---|---|
| `datasetIds` | Datasets to merge, in order (up to 100). Console: the dataset picker. API: dataset IDs or `username~dataset-name`. When given, `items` is ignored (OUTPUT says `itemsIgnored: true`). |
| `items` | Instead of datasets: up to 10,000 rows pasted as JSON — an array of row objects, or an array of row arrays (each inner array is merged like one dataset; `_sourceDataset` is then `items-1`, `items-2`, …, or `items` for a flat list). Prefilled with a small sample so a plain Start works; used only when `datasetIds` is empty. |
| `dedupFields` | Field(s) that identify a duplicate. Several fields = all must match. Nested: `address.city`, `images.0`. Empty = whole row. Rows that have **none** of these fields (or only empty values) are always kept and counted as `rowsWithoutKey`. |
| `keep` | `first` (default) keeps the earliest row; `last` keeps the latest (the datasets are then read twice — the first pass reads only the key fields when they are top-level). Output order is always dataset order, then row order. |
| `normalizeWhitespace` | Default on: `" Acme  Inc "` = `"Acme Inc"` when comparing. |
| `ignoreCase` | `"ACME"` = `"acme"` when comparing. |
| `ignoreTrailingSlash` | `https://a.com/x/` = `https://a.com/x` when comparing (only text containing `://`). |
| `ignoreFields` | Whole-row mode only: fields to leave out of the comparison, such as `scrapedAt`. Fields starting with `#` (Apify's hidden fields) are always left out. |
| `dedup` | Turn off to only merge and filter. |
| `fields` | Keep only these fields in the output. |
| `filter` | Conditions that all must match, applied **before** duplicates are removed: `[{"field": "price", "op": "gt", "value": 10}, {"field": "country", "op": "in", "value": ["US", "CA"]}]`. Ops: `equals`, `notEquals`, `contains`, `notContains`, `startsWith`, `endsWith`, `in`, `gt`, `gte`, `lt`, `lte`, `exists`, `notExists`, `isEmpty`, `isNotEmpty`. Text is compared case-insensitively; `contains` on a list checks its items; `gt`/`lt` compare numbers (`"1,299.50"` counts as a number; commas are read as thousands separators, so write decimals with a dot) or else text, which works for ISO dates like `2026-11-15`. |
| `addSourceDataset` | Adds `_sourceDataset` to each row: the dataset ID or `username~name` exactly as given in Datasets. |
| `maxItems` | Maximum output rows per run (default 100,000, up to 10 million). |

Numbers that are equal compare equal (`1` = `1.0`), but the number `1` and the text `"1"` are different keys.

### Use cases

- **Combine runs of the same scraper** (several cities, keywords or days) into one clean list without repeated listings, products or URLs.
- **Keep the latest version** of each item across daily runs: `keep: "last"`, deduplicate by `id` or `url`.
- **Clean before export**: drop rows with an empty price, keep only the columns your spreadsheet needs.
- **In a pipeline**: call it from an integration or another Actor after scrapers finish, with the dataset IDs they produced.

### Pricing

**$0.30 per 1,000 output rows** on the Free plan, **$0.25** on Bronze and **$0.20** on Silver and above (pay per event: one `apify-default-dataset-item` event per row in the result, plus Apify's standard actor-start event: $0.00005 per run up to 1 GB of memory, one more for each extra GB). **Duplicates, filtered-out rows and datasets that could not be read are not charged** — only rows in the result. Platform usage (compute, storage) is included in the price. Set **Max results** or a **maximum cost per run** to cap a run; it stops cleanly and keeps every row already saved.

### When a dataset can't be read

A dataset the actor may not read (not picked, a typo in the ID, someone else's private dataset, a URL instead of an ID) is **skipped, not fatal**: the other datasets are still merged, the run status says how many were skipped, and OUTPUT has the reason. If **no** dataset can be read, the run ends **FAILED** with the reason (nothing is charged). The fix is almost always to pick the dataset in the **Datasets** field or pass its exact ID — under limited permissions the platform grants access only to storages listed in that field.

### Limits — be aware

- **Memory**: only a 16-byte hash of each distinct key is kept, about 110 bytes per distinct key (190 with `keep: "last"`). With the default 1 GB that is roughly 4 million distinct keys (2.5 million with `last`); runs with more stop cleanly (`stoppedEarly: "memoryLimit"`) — give the run more memory. Very large rows (whole HTML pages) are read in smaller pages automatically.
- **Hash collisions**: two different keys could in theory get the same 128-bit hash and one row be dropped as a duplicate. The odds are negligible (far below one in a trillion even for billions of rows).
- **Datasets still being written**: rows added after a dataset was read are not included. With `keep: "last"` the second pass reads exactly the rows the first pass saw.
- **Per run**: default **Max results** is 100,000 rows — raise it for bigger merges. Up to 100 datasets, 10 million output rows, and 5 million rows fetched (with `keep: "last"` every row is fetched twice, so about 2.5 million rows). A row larger than 9 MB (Apify's limit) is skipped and counted as `rowsTooLarge`.
- **Timeouts**: the run stops taking new rows 60 seconds before its timeout, so the summary is always saved (`stoppedEarly: "timeLimit"`).
- No custom JavaScript transforms — filters and field selection cover the common cases without running user code.

### FAQ

**Can it read datasets from another account?** Only datasets your own account can read; pass the ID and it should work — if the platform refuses access, the dataset is skipped with the reason (tested with datasets in our own account).

**Does it change my original datasets?** No. It only reads them (READ permission) and writes the result to its own run dataset.

**Why is my row count lower than the sum of the datasets?** See OUTPUT: `duplicatesRemoved` and `filteredOut` per dataset.

**How do I dedupe on two columns?** `"dedupFields": ["name", "city"]` — rows are duplicates when both match.

### More tools from this developer

Other public actors by [dojito](https://apify.com/dojito):

- [Product Price & Stock Checker for US Online Stores](https://apify.com/dojito/us-product-price-stock) — price, currency, in-stock status, SKU/GTIN and brand from public product pages that publish schema.org Product data (Shopify, WooCommerce, BigCommerce, Magento and others).
- [ATS Job Board Feed](https://apify.com/dojito/ats-job-boards-feed) — every open job from Greenhouse, Lever, Ashby, Recruitee, Personio and Teamtailor boards in one schema, from their documented public APIs and feeds.
- [Sitemap URL Extractor](https://apify.com/dojito/sitemap-url-extractor) — every URL in a website's sitemaps with lastmod, changefreq, priority and hreflang alternates. Never downloads the pages themselves.
- [Wayback Machine Snapshot History](https://apify.com/dojito/wayback-snapshot-history) — every Internet Archive capture of a URL, folder or whole domain from the official CDX API, or one summary row per URL.
- [Domain RDAP & DNS Lookup](https://apify.com/dojito/domain-rdap-dns-lookup) — registered or available, registrar, created and expiry dates, nameservers and DNSSEC from the registry's RDAP server, plus DNS records. One row per domain.
- [Website Screenshot & PDF (Full Page, Mobile, Bulk URLs)](https://apify.com/dojito/website-screenshot-pdf) — full-page PNG / JPEG screenshots or A4 / Letter PDFs from a list of URLs, desktop to mobile sizes. One row per URL with file link, size, final URL and HTTP status.
- [Website Tech Stack Detector](https://apify.com/dojito/website-tech-stack-detector) — the CMS, ecommerce platform, analytics, tag manager, payment processor, CDN, framework and web server behind a website, from one home-page request per domain.
- [Bulk HTTP Request Runner (API Caller)](https://apify.com/dojito/bulk-http-request-runner) — send a list of HTTP requests to the APIs you choose and get one row per request: status, time, final URL and the response body (JSON parsed).

Using them together:

- **Checking a domain before you buy or link to it:** run Domain RDAP & DNS Lookup for registration status, expiry date and DNS, then Wayback Machine Snapshot History with Match = "Domain + subdomains" and Output = "Summary" to see when the site was first and last archived and how often its content changed.
- **Site migration or content audit:** list a site's URLs with Sitemap URL Extractor, then paste the pages you care about into Wayback Machine Snapshot History (Output = "Summary") to get each page's first and last capture.

***

Not affiliated with Apify beyond being published in its Store.

# Actor input Schema

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

The datasets to merge, in order (rows of the first dataset come first). Pick them from your storage, or over the API pass dataset IDs (or username~dataset-name) as strings. Up to 100. When you pick datasets here, the rows in 'Or: rows as JSON' below are ignored.

## `items` (type: `array`):

Instead of datasets, paste up to 10,000 rows: an array of row objects, or an array of row arrays (each inner array is merged like one dataset, in order). The two small sample groups (one duplicate URL) are only for trying the actor; when you pick Datasets above, they are ignored.

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

Rows with the same values in all these fields count as duplicates, e.g. url, or name + city. Nested fields with dots: address.city. Leave empty to compare whole rows. Rows with none of these fields are kept.

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

first = the earliest row (in dataset order, then row order). last = the latest row; the datasets are then read twice.

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

When comparing, trim text and treat runs of spaces / line breaks as one space. The output rows are not changed.

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

When comparing, treat "ACME" and "acme" as the same. The output rows are not changed.

## `ignoreTrailingSlash` (type: `boolean`):

When comparing, treat https://example.com/page/ and https://example.com/page as the same. The output rows are not changed.

## `ignoreFields` (type: `array`):

Only when 'Deduplicate by fields' is empty: leave these fields out of the comparison, e.g. scrapedAt or a run id that differs between otherwise equal rows. Fields starting with # are always ignored.

## `dedup` (type: `boolean`):

Turn off to only merge (and filter) the datasets.

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

Keep only these fields, in this order (dots reach nested values: address.city). Leave empty to keep the rows as they are.

## `filter` (type: `array`):

Keep only rows that match all conditions. Each condition: {"field": "price", "op": "gt", "value": 10}. op: equals, notEquals, contains, notContains, startsWith, endsWith, in (value = list), gt, gte, lt, lte, exists, notExists, isEmpty, isNotEmpty. Text is compared case-insensitively; gt/lt compare numbers, or text such as ISO dates.

## `addSourceDataset` (type: `boolean`):

Add a \_sourceDataset field: the dataset ID (or username~name) each row came from, exactly as given in Datasets.

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

Stop after this many output rows (you pay per output row). Duplicates and filtered-out rows are free.

## Actor input object example

```json
{
  "items": [
    [
      {
        "url": "https://example.com/shop/alpha",
        "name": "Alpha Coffee",
        "city": "Austin"
      },
      {
        "url": "https://example.com/shop/beta",
        "name": "Beta Books",
        "city": "Boston"
      }
    ],
    [
      {
        "url": "https://example.com/shop/beta",
        "name": "Beta Books",
        "city": "Boston"
      },
      {
        "url": "https://example.com/shop/gamma",
        "name": "Gamma Gym",
        "city": "Chicago"
      }
    ]
  ],
  "dedupFields": [
    "url"
  ],
  "keep": "first",
  "normalizeWhitespace": true,
  "ignoreCase": false,
  "ignoreTrailingSlash": false,
  "dedup": true,
  "filter": [],
  "addSourceDataset": false,
  "maxItems": 100000
}
```

# Actor output Schema

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

The rows that remain after filtering and removing duplicates. Each row is one paid result.

## `summary` (type: `string`):

JSON: rows read, duplicates removed, filtered out, rows out, and the same per dataset (with the reason any dataset could not be read). Free.

# 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 = {
    "items": [
        [
            {
                "url": "https://example.com/shop/alpha",
                "name": "Alpha Coffee",
                "city": "Austin"
            },
            {
                "url": "https://example.com/shop/beta",
                "name": "Beta Books",
                "city": "Boston"
            }
        ],
        [
            {
                "url": "https://example.com/shop/beta",
                "name": "Beta Books",
                "city": "Boston"
            },
            {
                "url": "https://example.com/shop/gamma",
                "name": "Gamma Gym",
                "city": "Chicago"
            }
        ]
    ],
    "dedupFields": [
        "url"
    ],
    "filter": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("dojito/merge-dedup-datasets").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 = {
    "items": [
        [
            {
                "url": "https://example.com/shop/alpha",
                "name": "Alpha Coffee",
                "city": "Austin",
            },
            {
                "url": "https://example.com/shop/beta",
                "name": "Beta Books",
                "city": "Boston",
            },
        ],
        [
            {
                "url": "https://example.com/shop/beta",
                "name": "Beta Books",
                "city": "Boston",
            },
            {
                "url": "https://example.com/shop/gamma",
                "name": "Gamma Gym",
                "city": "Chicago",
            },
        ],
    ],
    "dedupFields": ["url"],
    "filter": [],
}

# Run the Actor and wait for it to finish
run = client.actor("dojito/merge-dedup-datasets").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 '{
  "items": [
    [
      {
        "url": "https://example.com/shop/alpha",
        "name": "Alpha Coffee",
        "city": "Austin"
      },
      {
        "url": "https://example.com/shop/beta",
        "name": "Beta Books",
        "city": "Boston"
      }
    ],
    [
      {
        "url": "https://example.com/shop/beta",
        "name": "Beta Books",
        "city": "Boston"
      },
      {
        "url": "https://example.com/shop/gamma",
        "name": "Gamma Gym",
        "city": "Chicago"
      }
    ]
  ],
  "dedupFields": [
    "url"
  ],
  "filter": []
}' |
apify call dojito/merge-dedup-datasets --silent --output-dataset

```

## MCP server setup

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

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/VbmML8u1gB4aLp7Lx/builds/lOMX1Ru1aDz5a8iU9/openapi.json
