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

  • 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.6.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.6-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_json_diff-0.1.6.tar.gz
Algorithm Hash digest
SHA256 23e8a60838aa16e0854081f1eac82fa6a5397288dfb13e84b485e284e778db75
MD5 7ce7fe90f293f9c34e5a6b06a6490197
BLAKE2b-256 66407acb2aa1b16849747fdf27c3f73f1abd4f1072414802b607b46d3dd3256c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_json_diff-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1036c11953645cc057137f285ea0195f0b36f0a21ec3535b713dc23ff5c3e5da
MD5 07c5f6dc1d5dc3d1569f7d445cd1c8e7
BLAKE2b-256 36cb6d5e3357506837335e5265844286843b655950134e58cff6c614b6037ae9

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