Skip to main content

Readable JSON comparison with colorized terminal output

Project description

philiprehberger-json-diff

Tests PyPI version License

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

Function / Class Description
diff(old, new, ignore=None) Compare two dicts, returns list of Change objects
format_diff(changes, color=True) Format changes as readable string with optional ANSI colors
diff_summary(changes) Return dict with counts by change type

Development

pip install -e .
python -m pytest tests/ -v

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

philiprehberger_json_diff-0.1.7.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_json_diff-0.1.7-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_json_diff-0.1.7.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_json_diff-0.1.7.tar.gz
Algorithm Hash digest
SHA256 d7e0a2b19c1ea0309b65f30ed27c00fd52b10c2d563e2cd663243a1573e80f6f
MD5 a8985d41d042487794da2cfd890f739f
BLAKE2b-256 cb24eb9ec9ad542d6e7081a1a7f02d41e85ed145a003462d4c1b0cbb1ecf8518

See more details on using hashes here.

File details

Details for the file philiprehberger_json_diff-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_json_diff-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a48299a569d34053f2d6cd88c723b7c5152fb50ad8492fd7f71e39fed3777649
MD5 ff9e58c918130612a33d1c050f590046
BLAKE2b-256 e6206c39de0e9b35e6bcc013e06013a20e73560c562ab068983a48e007e5edfc

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