Skip to main content

jsonl-diff

Compare large JSONL, NDJSON, and top-level JSON arrays by record identity—not by line position—without loading either complete dataset into memory. Strict, deterministic, and disk-backed.

PyPI Python CI Coverage License

Install · Quick start · CLI · Python API · Semantics · Documentation


jsonl-diff reconciles two datasets using one or more top-level identity fields. It reports what is equal, added, deleted, modified, or duplicated while preserving the original OLD and NEW locations.

Core capabilities

  • Single or composite top-level identities.
  • Incremental JSONL/NDJSON and top-level JSON-array parsing.
  • Disk-backed, parallel indexing for large datasets.
  • Exact RFC 6901 ignore pointers.
  • JMESPath record filtering.
  • Configurable duplicate handling: error, first, or last.
  • Representation-sensitive numeric comparison.
  • Observed-schema drift for fields, types, nullability, and requiredness.
  • Deterministic JSONL details output.
  • Optional field-level RFC 6902 patches for modified records.
  • Local, HTTP/HTTPS, file-like, and compressed sources.
  • CLI and Python API backed by the same comparison engine.

Install

pip install jsonl-diff

Requires Python 3.10+.

Quick start

Given old.jsonl:

{"id":1,"name":"Ada"}
{"id":2,"name":"Grace"}

and new.jsonl:

{"id":2,"name":"Grace Hopper"}
{"name":"Ada","id":1}
{"id":3,"name":"Linus"}

compare by id:

jsonl-diff old.jsonl new.jsonl --key id
Records:
  equal:     1
  added:     1
  deleted:   0
  modified:  1
  OLD duplicates:  0
  NEW duplicates:  0

Property order and record order do not affect the result.

CLI

jsonl-diff [-h] --key KEY [--ignore IGNORE] [--where EXPRESSION]
           [--duplicates {error,first,last}] [--missing-key {error,null}]
           [--details FILE] [--field-diff] [--quiet]
           [--schema-diff] [--schema-ignore POINTER] [--format {jsonl,json}]
           old new
Option Purpose
old, new Local path, HTTP/HTTPS source, or - for stdin
--key KEY Top-level identity field; repeat or comma-separate for composite keys
--ignore POINTER RFC 6901 field pointer excluded from content comparison
--where EXPRESSION JMESPath filter evaluated against each record
--duplicates POLICY Reject duplicates or retain the first/last occurrence
--missing-key POLICY Reject absent identity fields or treat them as null
--details FILE Write the JSONL change report; must not be the OLD/NEW file
--field-diff Add RFC 6902 field patches to modified records; requires --details
--schema-diff Compare observed fields, types, nullability, and requiredness
--schema-ignore POINTER Exclude a pointer from observed-schema profiling
--format FORMAT Read jsonl (default) or one top-level JSON array with json
--quiet Suppress the human-readable summary

Common workflows

Composite identity

jsonl-diff old.jsonl new.jsonl --key country,customerId,type

Ignore volatile fields

jsonl-diff old.jsonl new.jsonl \
  --key id \
  --ignore /updated_at \
  --ignore /metadata/request_id

Filter participating records

jsonl-diff old.jsonl new.jsonl \
  --key id \
  --where 'deleted_at == `null`'

Allow a missing composite-key component

jsonl-diff old.jsonl new.jsonl \
  --key country,customerId \
  --missing-key null

Detect observed-schema drift

jsonl-diff old.jsonl new.jsonl \
  --key id \
  --schema-diff \
  --schema-ignore /metadata

Write a machine-readable change log

jsonl-diff old.jsonl new.jsonl \
  --key id \
  --details changes.jsonl \
  --quiet

Using the files from the quick start, changes.jsonl contains:

{"duplicates":"error","ignore":[],"key":["id"],"missing_key":"error","type":"meta","where":null}
{"key":[2],"new_line":1,"old_line":2,"op":"modified","type":"change"}
{"key":[3],"new_line":3,"op":"added","type":"change"}
{"added":1,"deleted":0,"equal":1,"modified":1,"new_duplicates":0,"old_duplicates":0,"type":"summary"}

The stream starts with comparison metadata, emits only changed identities in deterministic order, and finishes with the complete summary. See the details format for duplicate and schema events.

See which fields changed

jsonl-diff old.jsonl new.jsonl \
  --key id \
  --details changes.jsonl \
  --field-diff

Modified records gain an RFC 6902 patch (with the OLD value), followed by per-field totals:

{"key":[2],"new_line":1,"old_line":2,"op":"modified","patch":[{"old":"Grace","op":"replace","path":"/name","value":"Grace Hopper"}],"type":"change"}
{"added":0,"path":"/name","removed":0,"replaced":1,"type":"field_summary"}

See Field-level patches.

Get every report from a single indexing pass

Indexing dominates the cost of a comparison, and each invocation indexes both inputs again. Instead of running separate summary, schema, and details commands, request them together and query the details file afterwards:

jsonl-diff old.jsonl new.jsonl \
  --key id \
  --schema-diff \
  --details report.jsonl \
  --field-diff

# Later queries read report.jsonl instead of re-indexing the inputs.
jq -c 'select(.type == "schema_change")' report.jsonl
jq -c 'select(.type == "change" and .op == "modified")' report.jsonl
jq -c 'select(.type == "field_summary")' report.jsonl
jq -c 'select(.type == "summary")' report.jsonl

See Details format → Querying a report.

Read compressed inputs

jsonl-diff old.jsonl.xz new.jsonl.gz --key id

Read top-level JSON arrays

jsonl-diff old.json new.json --key id --format json

Exit codes

Code Meaning
0 No record, duplicate, or requested schema differences
1 Record differences, tolerated duplicates, or schema changes
2 Input, resource, output, or runtime failure
3 Invalid configuration or CLI usage (e.g. --details is OLD/NEW)

Python API

from jsonl_diff import ChangeOperation, diff


def main():
    with diff(
            "old.jsonl.gz",
            "new.jsonl.gz",
            key=("country", "customerId"),
            ignore=("/updated_at",),
            where='country == `"ES"`',
            schema_diff=True,
            field_diff=True,
    ) as result:
        print(result.summary)

        for change in result.changes(ChangeOperation.MODIFIED):
            print(change.key, change.old_line, change.new_line)
            for field in change.patch:
                print(" ", field.op, field.path, field.old, field.value)

        for item in result.field_summary():
            print(item.path, item.added, item.removed, item.replaced)

        for change in result.schema_changes():
            print(change.operation, change.path)


if __name__ == "__main__":
    main()

diff() returns a context-managed, disk-backed DiffResult. Entering the context completely validates and indexes both sources. Changes, duplicates, schema changes, and field summaries are then iterated lazily instead of being materialized in memory.

Applications must protect the entry point because indexing uses worker processes. See Parallel indexing for the multiprocessing requirements.

The immutable result models include:

  • Summary and SchemaSummary
  • Change and SourceLocation
  • FieldChange, FieldOperation, and FieldSummary (with field_diff=True)
  • Duplicate
  • SchemaChange and SchemaFieldProfile

The public exception hierarchy is rooted at JsonlDiffError:

  • ConfigurationError
  • InputError
  • DuplicateKeyError
  • ResourceError

See the Python API reference for the complete signature, models, iterator behavior, numeric key semantics, and error hierarchy.

Comparison semantics

The comparison is intentionally strict:

  • Each JSONL line must contain exactly one valid top-level object.
  • --format json requires one top-level array whose elements are records.
  • Blank lines, malformed JSON, NaN, and infinities are rejected.
  • Repeated object properties use last-wins semantics.
  • Identity fields are top-level JSON values; nested identity paths are not supported.
  • Object member order is ignored recursively; array order remains significant.
  • JSON types remain distinct: "1" is not 1, and true is not 1.
  • Parsed numeric representation remains significant: 1 is not 1.0, and 1.0 is not 1.00.
  • Unicode strings are compared without normalization.
  • Duplicate identities fail unless first or last is explicitly selected.
  • Changes are emitted in deterministic canonical-identity order.

--where decides which records participate. --key defines their identity. --ignore excludes fields from content comparison. --schema-ignore independently excludes fields from observed-schema profiling.

Read Comparison semantics for duplicate rules, ignore-pointer edge cases, filter order, schema inference, and numeric behavior.

Sources and compression

Source CLI Python API
Local path Yes Yes
HTTP/HTTPS URL Yes Yes
File-like object No Yes
gzip (.gz) Yes Yes
bzip2 (.bz2) Yes Yes
xz (.xz) Yes Yes
Zstandard (.zst) Python 3.14+ Python 3.14+
ZIP archive No No

Source opening and decompression are delegated to py-jsonl. File-like inputs and stdin are staged in the private temporary workspace so both indexing workers can reopen them.

Scope

jsonl-diff is a dataset reconciliation tool—not a visual or structural JSON editor. It intentionally does not provide:

  • line-position diffs or array element-level patches;
  • move or rename detection;
  • nested identities or automatic key detection;
  • fuzzy matching or numeric tolerances;
  • unordered-array comparison;
  • declared-schema validation or input repair;
  • ZIP, database, or cloud-provider inputs;
  • GUI or HTML reports.

Documentation

Guide Covers
Comparison semantics Identity, duplicates, ignores, filtering, numbers, and determinism
Disk-backed architecture SQLite indexes, temporary storage, cleanup, and source handling
Parallel indexing Worker lifecycle, database merge, recovery, and entry points
Details format Machine-readable JSONL event contract
Python API Complete signature, models, iterators, and errors

Development

uv sync --group test --group lint
# Lint
uv run ruff check --quiet --output-format=concise .
# Tests
uv run python -Wd -m pytest tests/ --cov

The suite covers CLI behavior, identity and canonicalization, validation, details output, field-level patches, source handling, compression, parallel indexing, and cleanup.

License

Licensed under the terms in LICENSE.

Metadata

Release files for jsonl-diff 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonl-diff 0.3.2
File Size Uploaded Provenance Actions
jsonl_diff-0.3.2.tar.gz 52.2 kB Without provenance Details for jsonl_diff-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jsonl-diff 0.3.2
File Interpreter ABI Platform Actions
jsonl_diff-0.3.2-py3-none-any.whl Python 3 none any Details for jsonl_diff-0.3.2-py3-none-any.whl

Total release size: 79.6 kB

Release files / jsonl_diff-0.3.2.tar.gz

Download URL jsonl_diff-0.3.2.tar.gz
Size 52.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3a2cca673ad642bdaafd236771b0c203bd452a0d06efd7274a5db0dbc3d1837a
BLAKE2b-256 checksum
How to use checksums
2d08337a8b3fc244512b2a4c989cda580d068de7eec05c60bd67abd43a2e2852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jsonl_diff-0.3.2-py3-none-any.whl

Download URL jsonl_diff-0.3.2-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f18d9c9b162b9aaf5d2a4b9058b5b3c691de6e2fbaa4cb138e3f74f28cb36c91
BLAKE2b-256 checksum
How to use checksums
e3ad03abd4fc9656c69a49caffe0782db50bb4f3bc3cf0ecfc2f7c8a3e1a1df3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for jsonl-diff 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page