Skip to main content

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 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

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.2.tar.gz (4.6 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.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for philiprehberger_json_diff-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4f640cb3645bbc7748aa7fc302916ddefc1425323c8ed99150358e3fead32987
MD5 4fe14eab3481a1d55753970136cc8e39
BLAKE2b-256 2ffffb3e4f11a01d396baa036ea1e965e37165e6852e28704a25f635379e3c99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_json_diff-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f3db239f4578cdf3a13c8190b95e830754f007695b1580886d3b2f8df88a599b
MD5 4339ae7a24572a27997d44a92f615cbc
BLAKE2b-256 90c786e1997d1628232b8a0aec390b57061f50c5a28fc24b7f1747221af539cf

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