# CSV & JSON Snapshot Reconciler (`grounded_goldeneye/csv-json-snapshot-reconciler`) Actor

Compare two CSV, JSON or JSONL snapshots by explicit keys. Find added, removed and changed records, duplicate keys, missing keys and type errors. Export JSON, spreadsheet-safe CSV and an HTML report.

- **URL**: https://apify.com/grounded_goldeneye/csv-json-snapshot-reconciler.md
- **Developed by:** [david tan](https://apify.com/grounded_goldeneye) (community)
- **Categories:** Developer tools
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.05 / completed reconciliation report

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

## CSV & JSON Snapshot Reconciler

Compare two snapshots by explicit unique keys and receive a reproducible data-quality and change report. Useful for product catalogs, inventory exports, authorized scraper outputs and migration checks.

Paste CSV, a JSON array of flat objects, or JSONL. The Actor identifies added, removed, modified and unchanged records, plus duplicate keys, missing keys, schema drift and optional type errors. No website login, source URL, AI API key or model calls are needed.

### Quick example

```json
{
  "beforeFormat": "csv",
  "beforeData": "id,name,price\n001,Keyboard,49\n002,Mouse,25\n003,Monitor,199\n",
  "afterFormat": "csv",
  "afterData": "id,name,price\n001,Keyboard,45\n003,Monitor,199\n004,Webcam,59\n",
  "keyColumns": ["id"],
  "expectedTypes": {"price": "number"}
}
```

Result: **1 added, 1 removed, 1 modified, 1 unchanged, 0 type errors**. Record order does not affect matching. For a composite key, use e.g. `"keyColumns": ["store_id", "product_id"]`.

### Outputs

| Output | Contents |
| --- | --- |
| Dataset summary | Complete counts only; one item per report |
| `REPORT.json` | Summary, schema changes, sampled differences and anomalies |
| `CHANGES.csv` | Spreadsheet-safe samples of additions, removals and field changes |
| `REPORT.html` | Standalone readable report; no scripts or external resources |

**Counts are complete; details are bounded samples.** `detailLimit` applies independently to each category (default/max 1,000). `detailTotals` and `truncated` indicate what was omitted. CSV and HTML use the same sampled data. Use `detailLimit: 0` for counts and schema only. Lower the limit when records are wide.

### Comparison rules

- Keys and values preserve types, case, spaces, leading zeros and Unicode. No automatic trimming, coercion or Unicode normalization.
- CSV cells are strings. JSON `1`, `1.0`, `true` and `"1"` are distinct; matching CSV and JSON sources may require you to align their types first.
- Field missing, JSON `null` and empty string are distinct values. Missing/null/empty key components are missing-key anomalies.
- If a key is duplicated on **either** side, all rows with that key on **both** sides are isolated as ambiguous. They are never arbitrarily paired or counted as additions/removals.
- `compareColumns` omitted means compare all fields. Explicit `[]` compares no value fields. Schema changes are always shown.
- `expectedTypes` checks values without changing them. Types: `string`, `integer`, `number`, `boolean`, `null`. Missing expected fields are errors. CSV integer checks use canonical decimal syntax; CSV booleans use lowercase `true`/`false`; numeric checks reject nonfinite values.
- JSON field order is irrelevant. Difference order follows the old snapshot for modifications/removals, and the new snapshot for additions.

### Limits and errors

Combined source text: **5 MiB UTF-8**. Each side: **10,000 records**, **100 distinct columns**, flat scalar values only. Field name: **256 UTF-8 bytes**. Cell: **32,768 serialized UTF-8 bytes**, including JSON string quoting/escaping. Report exports: **10 MiB combined**. Core work limit: **30 seconds**; deployment timeout: **60 seconds**. Actor memory is fixed at **256 MB**.

CSV requires unique nonempty headers and consistent field counts. JSON rejects duplicate fields, nested values, invalid Unicode, NaN/Infinity and malformed records. JSONL ignores empty lines. CSV blank records with the wrong field count are errors. An empty JSON array is supported. Structural/size errors fail clearly instead of silently dropping records. Type and key anomalies remain in successful reports.

### Pricing

This Actor is designed for **one `report-generated` event per completed report**, independent of row count. Check the current price shown in Apify before running. Report files and summary are saved before the report event is charged. No report event is charged for invalid input or failed delivery. A platform startup event, if enabled in the published pricing, can still apply to unsuccessful runs.

### Data handling

Provide only data you are authorized to process. The Actor does not fetch external URLs or call an AI service. Source records are not written to logs or the summary dataset, but differences and anomalies can appear in report files. Run inputs and output storage are retained by Apify according to your account settings; this is **not** a zero-retention service. Delete run storage when no longer needed. Exported CSV prefixes formula-like text to reduce spreadsheet formula injection; JSON retains the original values.

### Local use

```bash
python3 -m reconcile --input examples/input.json --output state/demo
python3 -m unittest discover -s tests -v
```

The local core uses Python 3.12 standard libraries and performs no network calls. The cloud wrapper uses pinned Apify SDK dependencies.

# Actor input Schema

## `beforeFormat` (type: `string`):

CSV with header, JSON array of flat objects, or one flat JSON object per nonempty line.

## `beforeData` (type: `string`):

Inline source text. CSV headers are required; JSON input must be a flat-object array. CSV values remain strings.

## `afterFormat` (type: `string`):

Choose the format of the current source text.

## `afterData` (type: `string`):

Inline source text, within the combined 5 MiB limit.

## `keyColumns` (type: `array`):

One key or a composite key, in order. Exact, case-sensitive and type-sensitive; no trimming. Keys duplicated on either side are isolated on both sides.

## `delimiter` (type: `string`):

Used for both CSV snapshots. Ignored for JSON and JSONL.

## `compareColumns` (type: `array`):

Omit this option to compare all columns. An explicitly empty list compares no value fields; schema changes are always reported.

## `expectedTypes` (type: `object`):

Map names to string, integer, number, boolean or null. Example: {"price":"number"}. Checks do not convert values. CSV integers use canonical decimal syntax and booleans use true/false.

## `detailLimit` (type: `integer`):

Complete counts are always calculated. Each category contains up to this many detail samples; truncated flags identify omitted details. Lower this for large/wide records.

## Actor input object example

```json
{
  "beforeFormat": "csv",
  "beforeData": "id,name,price\n001,Keyboard,49\n002,Mouse,25\n003,Monitor,199\n",
  "afterFormat": "csv",
  "afterData": "id,name,price\n001,Keyboard,45\n003,Monitor,199\n004,Webcam,59\n",
  "keyColumns": [
    "id"
  ],
  "delimiter": ",",
  "expectedTypes": {},
  "detailLimit": 1000
}
```

# Actor output Schema

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

One summary item with complete counts; does not contain source records.

## `jsonReport` (type: `string`):

Schema, typed differences, anomalies, complete counts and detail truncation flags.

## `csvChanges` (type: `string`):

Sampled additions, removals and per-field modifications, escaped for spreadsheets.

## `htmlReport` (type: `string`):

Standalone, escaped report without external resources or JavaScript.

# 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 = {
    "beforeData": `id,name,price
001,Keyboard,49
002,Mouse,25
003,Monitor,199`,
    "afterData": `id,name,price
001,Keyboard,45
003,Monitor,199
004,Webcam,59`
};

// Run the Actor and wait for it to finish
const run = await client.actor("grounded_goldeneye/csv-json-snapshot-reconciler").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 = {
    "beforeData": """id,name,price
001,Keyboard,49
002,Mouse,25
003,Monitor,199
""",
    "afterData": """id,name,price
001,Keyboard,45
003,Monitor,199
004,Webcam,59
""",
}

# Run the Actor and wait for it to finish
run = client.actor("grounded_goldeneye/csv-json-snapshot-reconciler").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 '{
  "beforeData": "id,name,price\\n001,Keyboard,49\\n002,Mouse,25\\n003,Monitor,199\\n",
  "afterData": "id,name,price\\n001,Keyboard,45\\n003,Monitor,199\\n004,Webcam,59\\n"
}' |
apify call grounded_goldeneye/csv-json-snapshot-reconciler --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,grounded_goldeneye/csv-json-snapshot-reconciler"
        }
    }
}
```

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/gOS3qUrWSYPP9hqJZ/builds/JoCwOYABTYQN4mkvc/openapi.json
