# Dataset Deduplicate & Merge - Remove Duplicates, JSON & CSV (`wood-between-studio/dataset-dedup-merge`) Actor

Merge Apify datasets and JSON, JSONL or CSV files, then remove duplicates by any fields. Pick, rename and filter fields, keep first or last, output only new items. Works with limited permissions. $0.01 per 1,000 items.

- **URL**: https://apify.com/wood-between-studio/dataset-dedup-merge.md
- **Developed by:** [Wood Between Studio](https://apify.com/wood-between-studio) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 90.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.01 / 1,000 unique item saveds

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 Deduplicate & Merge: Remove Duplicates from Apify Datasets, JSON & CSV

**Merge any number of Apify datasets and JSON, JSON Lines or CSV files into one clean dataset, and remove duplicates** by the fields you choose (URL, ID, title + company, anything). Keep the first or last copy, get **only new items** compared with older runs, and pick, rename, drop or require fields on the way. It runs with **limited permissions**: it can only read the datasets you pick, nothing else in your account.

### Why use it?

- **Reliable with limited permissions.** Datasets are chosen with the standard Apify dataset picker and opened read-only, so runs don't fail with "insufficient permissions".
- **Dedup by any fields**, including nested dot paths (`location.city`), or by the whole item.
- **Loose matching** (on by default): ignores case, extra spaces, `http://` vs `https://`, `www.` and trailing slashes, so `https://www.Site.com/a/` and `site.com/a` count as the same.
- **Only new items.** Point `onlyNewSince` at last week's datasets and get just the items you have not seen before. Ideal after a scheduled scraper run.
- **Keep first or last.** Use "last" to let newer datasets overwrite older ones.
- **Mix sources.** Apify datasets plus public JSON, JSONL or CSV URLs (exports, GitHub raw files, Google Sheets CSV links).
- **Shape the output.** Keep only some fields, remove fields, rename columns, drop items missing required fields, add a `_source` column.
- **Cheap and fair.** $0.01 per 1,000 unique items saved. Duplicates and dropped items are free.

### Use cases

- Combine results of several scraper runs (Google Maps, jobs, products, real-estate listings) into one list without duplicates
- Daily or weekly "what's new" feeds: only new listings, jobs, posts or products since the last run
- Clean a CSV or JSON export before importing it into a CRM, spreadsheet or database
- Merge datasets from different Actors and rename their columns to one schema

### Input

| Field | Default | Notes |
|---|---|---|
| `datasetIds` | | Your datasets (picker, IDs or names). Merged in order |
| `fileUrls` | | Public JSON, JSONL or CSV URLs |
| `dedupFields` | whole item | e.g. `["url"]` or `["title", "company"]` |
| `keep` | `first` | `first` or `last` |
| `normalize` | `true` | Loose matching of dedup values |
| `onlyNewSince` | | Older datasets; items already in them are dropped |
| `fields` / `omitFields` | | Keep only / remove fields (dot paths OK) |
| `rename` | | `{"Title": "title"}` |
| `requireFields` | | Drop items where these are empty |
| `addSourceField` | `false` | Adds `_source` |
| `outputDuplicates` | `false` | Saves removed duplicates to a separate dataset (free) |
| `maxItems` | `0` | Cap on unique items (0 = none) |

```json
{
  "datasetIds": ["YOUR_DATASET_ID_1", "YOUR_DATASET_ID_2"],
  "dedupFields": ["url"],
  "keep": "last",
  "fields": ["url", "title", "price"]
}
```

### Output

The default dataset holds the unique items (with your field changes). The `SUMMARY` record in the key-value store shows counts per source:

```json
{
  "itemsRead": 205, "uniqueItemsSaved": 10, "duplicatesRemoved": 190, "alreadyKnownRemoved": 0, "droppedMissingFields": 5,
  "dedupFields": ["userId"], "keep": "first",
  "sources": [{ "source": "dataset:abc123", "items": 100, "error": null }],
  "chargedItems": 10
}
```

### Pricing

**$0.01 per 1,000 unique items saved** ($0.00001 per item). Platform usage is included. Items read but removed as duplicates, already-known items, items missing required fields and failed sources are not charged. Set a maximum charge per run for a hard cap; the Actor stops cleanly when it is reached.

### Limits and tips

- Order matters: with `keep: "first"`, earlier datasets win; with `"last"`, later ones win.
- For tens of millions of items, raise memory (each unique key uses about 100 bytes).
- CSV files need a header row. JSON files can be an array, an object with `items`/`data`, or JSON Lines.
- File URLs must be public. Only use data you have the right to process.

### Support

Need fuzzy matching, a different output format or a feature? Open an issue on the **Issues** tab. We read every one.

### Call it from curl, JavaScript or Python

You can run this Actor in the [Apify Console](https://apify.com/wood-between-studio/dataset-dedup-merge) with no code, or call it as an API from curl, JavaScript or Python. Replace `YOUR_TOKEN` with an [Apify API token](https://console.apify.com/account/integrations).

#### curl

```bash
curl "https://api.apify.com/v2/acts/wood-between-studio~dataset-dedup-merge/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"datasetIds": ["YOUR_DATASET_ID_1", "YOUR_DATASET_ID_2"], "dedupFields": ["url"], "keep": "last"}'
```

#### JavaScript

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

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('wood-between-studio/dataset-dedup-merge').call({
  "datasetIds": [
    "YOUR_DATASET_ID_1",
    "YOUR_DATASET_ID_2"
  ],
  "dedupFields": [
    "url"
  ],
  "keep": "last"
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);
```

#### Python

```python
import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("wood-between-studio/dataset-dedup-merge").call(run_input={
  "datasetIds": [
    "YOUR_DATASET_ID_1",
    "YOUR_DATASET_ID_2"
  ],
  "dedupFields": [
    "url"
  ],
  "keep": "last"
})
items = client.dataset(run["defaultDatasetId"]).list_items().items
print(items)
```

You can also schedule the Actor, cap the spend per run, and send the dataset to Google Sheets, Slack or a webhook from the Console. Store page: [apify.com/wood-between-studio/dataset-dedup-merge](https://apify.com/wood-between-studio/dataset-dedup-merge).

# Actor input Schema

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

Pick one or more of your datasets (or paste IDs/names). They are merged in this order. The Actor gets read-only access to just these datasets.

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

Optional public URLs of JSON arrays, JSON Lines or CSV files (e.g. an Apify dataset export link, a GitHub raw file). Merged after the datasets. The prefilled example merges the same 10-user file twice so you can see duplicates removed.

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

Items with the same values in ALL of these fields are duplicates (e.g. url, or title + company). Dot paths work (address.city). Leave empty to compare whole items.

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

Keep the first occurrence (earlier datasets win) or the last one (later datasets win, useful for updates).

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

Trim spaces, ignore letter case and trailing slashes when comparing dedup fields.

## `onlyNewSince` (type: `array`):

Optional. Items whose dedup key already exists in these older datasets are dropped, so you get only NEW items (great for scheduled scrapes).

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

Optional. Output only these fields (dot paths allowed). Leave empty to keep all.

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

Optional. Fields to drop from every item.

## `rename` (type: `object`):

Optional. Map of old name to new name, e.g. {"Title": "title"}.

## `requireFields` (type: `array`):

Optional. Items where any of these fields is empty, null or missing are dropped.

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

Add which dataset or file each item came from.

## `outputDuplicates` (type: `boolean`):

Save the removed duplicates to a separate dataset named in the SUMMARY (not charged).

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

Safety cap on unique items saved (0 = no cap).

## Actor input object example

```json
{
  "fileUrls": [
    "https://jsonplaceholder.typicode.com/users",
    "https://jsonplaceholder.typicode.com/users"
  ],
  "dedupFields": [
    "id"
  ],
  "keep": "first",
  "normalize": true,
  "addSourceField": true,
  "outputDuplicates": false,
  "maxItems": 0
}
```

# 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 = {
    "fileUrls": [
        "https://jsonplaceholder.typicode.com/users",
        "https://jsonplaceholder.typicode.com/users"
    ],
    "dedupFields": [
        "id"
    ],
    "addSourceField": true
};

// Run the Actor and wait for it to finish
const run = await client.actor("wood-between-studio/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 = {
    "fileUrls": [
        "https://jsonplaceholder.typicode.com/users",
        "https://jsonplaceholder.typicode.com/users",
    ],
    "dedupFields": ["id"],
    "addSourceField": True,
}

# Run the Actor and wait for it to finish
run = client.actor("wood-between-studio/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 '{
  "fileUrls": [
    "https://jsonplaceholder.typicode.com/users",
    "https://jsonplaceholder.typicode.com/users"
  ],
  "dedupFields": [
    "id"
  ],
  "addSourceField": true
}' |
apify call wood-between-studio/dataset-dedup-merge --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,wood-between-studio/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/Khjy3ZyW5Tw1yS1NW/builds/VKz40XyF4fgzIxHAO/openapi.json
