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 found2— 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-colorflag
v0.4.0 — Smart list diffing (current)
- Match list items by key field (
list_keyparameter) - Support for multiple fallback keys
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fcce2368beebaf098336f5dab924b34cdd335e46133f2cc3fb0c2cbaf94d7f1
|
|
| MD5 |
70807f981627b2808abc42652a4a4e8a
|
|
| BLAKE2b-256 |
0488ca02ca9b3ba04998f59a2534549b4fcaef053628eb7a4644416af69b92c6
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
json_diff_lite-0.4.0.tar.gz -
Subject digest:
6fcce2368beebaf098336f5dab924b34cdd335e46133f2cc3fb0c2cbaf94d7f1 - Sigstore transparency entry: 729369636
- Sigstore integration time:
-
Permalink:
nilerbarcelos/json-diff-lite@76c91af646ea775514b649af15a884590d5f8b1e -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/nilerbarcelos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@76c91af646ea775514b649af15a884590d5f8b1e -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e764ecd6a51ab0834707a2fa2dc17ee27bd16729944c86efd281b2a723c01a49
|
|
| MD5 |
eeb9d0c54635263d28a67516d5a6336f
|
|
| BLAKE2b-256 |
a89795ef767b70a596cd2530121f858a959befa50d5b070e3b037ac80d5f2751
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
json_diff_lite-0.4.0-py3-none-any.whl -
Subject digest:
e764ecd6a51ab0834707a2fa2dc17ee27bd16729944c86efd281b2a723c01a49 - Sigstore transparency entry: 729369653
- Sigstore integration time:
-
Permalink:
nilerbarcelos/json-diff-lite@76c91af646ea775514b649af15a884590d5f8b1e -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/nilerbarcelos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@76c91af646ea775514b649af15a884590d5f8b1e -
Trigger Event:
release
-
Statement type: