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 WHERE]
           [--duplicates {error,first,last}] [--missing-key {error,null}]
           [--details FILE] [--field-diff] [--schema-diff]
           [--schema-ignore POINTER] [--quiet] [--format {jsonl,json}]
           old new
Option Purpose
old, new Local path, file:// or HTTP/HTTPS URL, or - for stdin (not both)
--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

Each invocation indexes both inputs again, so request the reports 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 == "change" and .op == "modified")' 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 (str/Path) Yes Yes
file:// or HTTP/HTTPS URL Yes Yes
Standard input (-) Yes No
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 (see Architecture).

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 Identity, duplicates, filtering, and comparison rules
Architecture SQLite index, temporary storage, cleanup, and sources
Parallel indexing Workers, recovery, and application entry points
Details format JSONL report contract
Python API 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

License

Licensed under the terms in LICENSE.

Metadata

Release files for jsonl-diff 0.3.3

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.3
File Size Uploaded Provenance Actions
jsonl_diff-0.3.3.tar.gz 53.9 kB Without provenance Details for jsonl_diff-0.3.3.tar.gz

Built distribution (wheel)

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

Total release size: 82.6 kB

Release files / jsonl_diff-0.3.3.tar.gz

Download URL jsonl_diff-0.3.3.tar.gz
Size 53.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3c2a0b4d353e747836835ed2bb79ada9ea041305e928bac3240472e2923835ea
BLAKE2b-256 checksum
How to use checksums
3836bd98695dc4e64951baa600f410404e0f165fabbc572927b1529f3c0c821b
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.3-py3-none-any.whl

Download URL jsonl_diff-0.3.3-py3-none-any.whl
Size 28.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56363d188d00888875f11b094125af408acca4cbace33abbc30764c57b638129
BLAKE2b-256 checksum
How to use checksums
5f1b54b387f00091d11c7503b0da9c3a2bd763e48c73a668ec548eb2c370a352
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.3

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