Readable JSON comparison with colorized terminal output
Project description
philiprehberger-json-diff
Readable JSON/dict comparison with colorized terminal output.
Installation
pip install philiprehberger-json-diff
Usage
from philiprehberger_json_diff import diff, format_diff, diff_summary
old = {"name": "Alice", "age": 30, "city": "NYC"}
new = {"name": "Alice", "age": 31, "country": "US"}
changes = diff(old, new)
# Pretty-print with colors
print(format_diff(changes))
# Get a summary
summary = diff_summary(changes)
# {"added": 1, "removed": 1, "modified": 1, "total": 3}
Nested Comparison
old = {"user": {"name": "Alice", "settings": {"theme": "dark"}}}
new = {"user": {"name": "Alice", "settings": {"theme": "light"}}}
changes = diff(old, new)
# Reports: modified user.settings.theme: 'dark' -> 'light'
Ignore Paths
changes = diff(old, new, ignore={"user.settings.theme"})
API
diff(old, new, ignore=None)— Compare two dicts, returns list ofChangeobjectsformat_diff(changes, color=True)— Format changes as readable string with optional ANSI colorsdiff_summary(changes)— Return dict with counts by change type
Development
pip install -e .
python -m pytest tests/ -v
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 philiprehberger_json_diff-0.1.5.tar.gz.
File metadata
- Download URL: philiprehberger_json_diff-0.1.5.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
569178e604e819f44b7963d787d5ff397bc2ad9547d91490ab2e3348e2b05954
|
|
| MD5 |
6793810699af6de8b0e582684896d94f
|
|
| BLAKE2b-256 |
4828535bda730d5e74b62c9641566af240ea334c38fb3d9295665e55d75432f0
|
File details
Details for the file philiprehberger_json_diff-0.1.5-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_json_diff-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecc5725c4c6b960b8cf97f48915e22374337df9772e3f850210200ba4269dfc0
|
|
| MD5 |
3dc3eadefd603814ef151d9ba2136906
|
|
| BLAKE2b-256 |
2ad932d4e107651edbe7c3ce7ca39e326b1615135a9acd178b3c36076303effa
|