# Dataset Dedupe + Schema Cleanup (`zengdonghunter/dataset-dedupe-schema-cleanup`) Actor

Clean, deduplicate, normalize, and schema-check JSON datasets with a simple structured input.

- **URL**: https://apify.com/zengdonghunter/dataset-dedupe-schema-cleanup.md
- **Developed by:** [AI Bounty Miner Hunter](https://apify.com/zengdonghunter) (community)
- **Categories:** Agents, AI, Jobs
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## 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 Dedupe + Schema Cleanup

Clean, deduplicate, normalize, and schema-check JSON datasets with structured input.

### What it does

- Removes duplicate records using selected keys.
- Trims and normalizes supported fields.
- Validates records against optional schema rules.
- Separates invalid records from clean records.
- Returns a summary of the cleanup.
- Writes clean records to the run's default Apify Dataset.
- Writes the complete result to `OUTPUT` in the run's default Key-value store.

### Example input

```json
{
  "records": [
    {"email": " alice@example.com ", "name": "Alice"},
    {"email": "alice@example.com", "name": "Alice"},
    {"email": "bob@example.com", "name": "Bob"}
  ],
  "dedupeKeys": ["email"],
  "normalization": {
    "trimStrings": true
  }
}
```

### Expected result

- 3 input records
- 2 clean records
- 1 duplicate removed
- 0 invalid records

### Output

The `OUTPUT` object contains:

- `cleanRecords`: normalized records that passed validation and were not duplicates.
- `removedDuplicates`: records removed because their selected dedupe-key values matched an earlier record.
- `invalidRecords`: records that failed the optional schema or rules.
- `summary`: counts for input, clean, duplicate, and invalid records.

Clean records are also written as individual items to the default Apify Dataset for tabular inspection and downstream integrations.

### Limits and safety

- Maximum 5,000 records.
- Maximum 1 MB serialized input.
- Bounded execution.
- No URLs, scraping, or arbitrary code.
- No external network access is required.

### Use in Apify

In Apify Console, open the Actor, enter the JSON input, and click **Start**. After the run completes, use the **Dataset** tab for clean records and the **Key-value store** tab to open the `OUTPUT` record.

For API or SDK runs, send the same JSON object as the Actor input. Read the run's default Dataset for `cleanRecords`, and retrieve the default Key-value store record named `OUTPUT` for the complete result. The Actor's generated input and output schemas are also available in Console and through the Apify API.

# Actor input Schema

## `records` (type: `array`):

JSON records to clean; maximum 5,000 records and 1 MB serialized input.

## `dedupeKeys` (type: `array`):

Fields whose values identify duplicate records.

## `targetSchema` (type: `object`):

Optional field type requirements: string, number, boolean, or required.

## `normalization` (type: `object`):

Optional safe normalization flags: trimStrings and lowercaseKeys.

## Actor input object example

```json
{
  "records": [
    {
      "id": "1",
      "email": "test@example.com",
      "name": "Example User"
    },
    {
      "id": "1",
      "email": "test@example.com",
      "name": "Example User"
    }
  ],
  "dedupeKeys": [
    "id"
  ],
  "targetSchema": {},
  "normalization": {}
}
```

# Actor output Schema

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

No description

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

// Run the Actor and wait for it to finish
const run = await client.actor("zengdonghunter/dataset-dedupe-schema-cleanup").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("zengdonghunter/dataset-dedupe-schema-cleanup").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 zengdonghunter/dataset-dedupe-schema-cleanup --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,zengdonghunter/dataset-dedupe-schema-cleanup"
        }
    }
}
```

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/dUcs9zusbktdxfQrs/builds/fvnQfzwBGG5xYPSTT/openapi.json
