Skip to main content

A minimal, zero-dependency library for comparing JSON objects with human-readable output

Project description

json-diff-lite

A minimal, zero-dependency Python library for comparing JSON objects with human-readable output.

Why?

Existing JSON diff libraries have their drawbacks:

Library Issue
deepdiff Powerful but heavy, complex output
jsondiff Unintuitive API, hard to interpret results
dictdiffer Output as technical tuples, not human-friendly
difflib Operates on strings, not structured JSON

json-diff-lite is designed to be:

  • Zero dependencies
  • Minimal API
  • Human-readable output
  • Perfect for logs, debugging, and CI

Installation

pip install json-diff-lite

Usage

from json_diff_lite import diff

old = {
    "name": "Ana",
    "age": 30,
    "address": {"street": "Rua A", "number": 100}
}

new = {
    "name": "Ana Maria",
    "age": 31,
    "address": {"street": "Rua B", "number": 100}
}

changes = diff(old, new)
for change in changes:
    print(change)

Output:

~ address.street: 'Rua A' -> 'Rua B'
~ age: 30 -> 31
~ name: 'Ana' -> 'Ana Maria'

Output format

  • + key: value — Added
  • - key: value — Removed
  • ~ key: old -> new — Modified

Smart list matching

By default, lists are compared by index. Use list_key to match items by a field:

old = {"users": [{"id": 1, "name": "Ana"}, {"id": 2, "name": "Bob"}]}
new = {"users": [{"id": 2, "name": "Bob"}, {"id": 1, "name": "Ana Maria"}]}

# Without list_key (compares by index - shows many false changes)
diff(old, new)

# With list_key (matches by id field)
changes = diff(old, new, list_key="id")
for change in changes:
    print(change)

Output:

~ users[id=1].name: 'Ana' -> 'Ana Maria'

You can also provide multiple keys as fallback:

diff(old, new, list_key=["id", "name", "key"])

Supported types

  • Dicts (recursive)
  • Lists (index-based or key-based comparison)
  • Primitives: str, int, float, bool, None

CLI

Compare JSON files directly from the command line:

json-diff-lite file1.json file2.json

Options:

  • -q, --quiet — Exit with code 1 if differences found, no output
  • --no-color — Disable colored output
  • -v, --version — Show version

Colors are automatically enabled when outputting to a terminal:

  • Green for additions (+)
  • Red for removals (-)
  • Yellow for modifications (~)

Exit codes:

  • 0 — No differences (or version shown)
  • 1 — Differences found
  • 2 — Error (file not found, invalid JSON)

Limitations

Current version (v0.4.0) does not support:

  • Custom objects
  • Unordered comparison tolerance

These features may be added in future releases.

Development

# Clone the repository
git clone https://github.com/nilerbarcelos/json-diff-lite.git
cd json-diff-lite

# Install dev dependencies
pip install hatch

# Run tests
hatch run test:run

Roadmap

v0.1.0 — MVP

  • Basic diff for dict/list/primitives
  • Human-readable output
  • Tests

v0.2.0 — CLI

  • Command-line interface
  • Quiet mode for CI

v0.3.0 — Colored output

  • ANSI colors (auto-detected)
  • --no-color flag

v0.4.0 — Smart list diffing (current)

  • Match list items by key field (list_key parameter)
  • Support for multiple fallback keys

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_diff_lite-0.4.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_diff_lite-0.4.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file json_diff_lite-0.4.0.tar.gz.

File metadata

  • Download URL: json_diff_lite-0.4.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for json_diff_lite-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6fcce2368beebaf098336f5dab924b34cdd335e46133f2cc3fb0c2cbaf94d7f1
MD5 70807f981627b2808abc42652a4a4e8a
BLAKE2b-256 0488ca02ca9b3ba04998f59a2534549b4fcaef053628eb7a4644416af69b92c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for json_diff_lite-0.4.0.tar.gz:

Publisher: python-publish.yml on nilerbarcelos/json-diff-lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file json_diff_lite-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: json_diff_lite-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for json_diff_lite-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e764ecd6a51ab0834707a2fa2dc17ee27bd16729944c86efd281b2a723c01a49
MD5 eeb9d0c54635263d28a67516d5a6336f
BLAKE2b-256 a89795ef767b70a596cd2530121f858a959befa50d5b070e3b037ac80d5f2751

See more details on using hashes here.

Provenance

The following attestation bundles were made for json_diff_lite-0.4.0-py3-none-any.whl:

Publisher: python-publish.yml on nilerbarcelos/json-diff-lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page