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

Supported types

  • Dicts (recursive)
  • Lists (index-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.3.0) does not support:

  • Smart list matching (by similarity or ID)
  • Custom objects
  • Unordered comparison tolerance

These features are planned for 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 (current)

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

v0.4.0 — Smart list diffing

  • Match list items by similarity

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.3.0.tar.gz (6.2 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.3.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: json_diff_lite-0.3.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for json_diff_lite-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e7790816eda35ebc1c7807376f93d9b2c5cec8aa955eab5bbe9dbc031b9fa0f9
MD5 13b872dbbea7e6daa5917913e741bb1c
BLAKE2b-256 94f4934484bffe2ca53593bc2ee787c15c1dc6152036a9501f3286d97467a151

See more details on using hashes here.

File details

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

File metadata

  • Download URL: json_diff_lite-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for json_diff_lite-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6123a1e12bfac4431c91e235c5b9c1817d514744dd093bdfd83199720eabceb
MD5 1124c33d6188d3ac5b085e4a08fc961d
BLAKE2b-256 708aa795186a51a6db5fcc4c45f770f7d2ea9e3931a8157770869c601c2d2fa5

See more details on using hashes here.

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