Skip to main content

A library to compare any json string/bytes/json-like-objects.

Version 1.20 is an enhance version that supports omit_path to ignore omitted keys in dict, and fixes many bugs, esp counting message inaccurate issue when same length & element collections; and wrong not_found info when different length under ignore_list_seq=True

Version 1.19 is an enhance version that fixes small bugs with strict_number_type supported to make 1 != 1.0.

Version 1.18 is a quickfix + enhance version that fixes custom handlers cannot be passed recursively bug, and float_fuzzy_digits can be passed directly.

Version 1.17 is an enhance version that supports custom handlers to handle outputs.

Version 1.16 is a quickfix version that supports Python 3.8.

Features

  • Compare jsons and print the differences (what and where they are, recursion supported). Useful for interface testing.

  • Config whether it will ignore the order of items in a list or not, recursively.

  • Both python 26+ and 35+ supported.

  • Regular expressions supported for string to skip unconcerned keys or just to assert the format.

  • Compact str and unicode (or bytes and str in python3), they are considered equal. Good for non ascii coding languages.

  • Both json string (unicode or binary str) and json object (dict, list or tuple) are supported.

  • Support tuples, so results from pymysql.cursors.DictCursor can compare with interface response directly.

  • Json type legal check.

  • Support skipping anywhere using argument like ignore_path=[“/a/1/k”, “/a/1/l”], dict keys or list indexes. Skipped fields are regarded as match.

  • The ignore_path list now support regular expressions too. You can use [r“^(/:raw-latex:`d+`/a)”] as ignore_path to skip all keys named “a” in [{“a”: 1, “b”: 2}, {“a”: 1, “b”: 4}] but still compare the value of “b”. (New)

    • Useful when compare multi records in database query result (dictionary cursor) with some fields unconcerned.

  • Fuzzy equal when handling floats. (New)

  • Python 3.8 supported. (New)

  • Custom handlers supported. (New)

  • Strict_number_type option to make int(1) != float(1.0) supported. (New)

QuickStart

install

pip install jsoncomparedeep

or update

pip install -U jsoncomparedeep

a simple example

from json_compare import Jcompare
cp=Jcompare()
print(cp.compare({"key1":["v1","v2"],"key2":{"key3":1}},{"key1":["v2","v1"],"key2":{"key3":2}}))

to see

a is {'key2': {'key3': 1}, 'key1': ['v1', 'v2']}
b is {'key2': {'key3': 2}, 'key1': ['v2', 'v1']}
ignore_list_seq = True, re_compare = True
different value at /key2/key3
a: 1
b: 2
False

For more demos and information, just install it and visit the test file test_json_compare.py in Your_Python_Path/Lib/site-packages/json_compare/

Small Hints

  • Datetime in SQL result is not JSON serializable type, use something like CAST(create_time as CHAR) ‘create_time’ in SQL statement to solve it.

Bug report

  • Issues and bugs report to rainydew@qq.com.

  • Homepage icon leads to my Github project page, issues / PRs / stars are welcomed :)

Release files for jsoncomparedeep 1.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsoncomparedeep 1.20
File Size Uploaded
jsoncomparedeep-1.20.tar.gz 8.8 kB Details

Release files / jsoncomparedeep-1.20.tar.gz

Download URL jsoncomparedeep-1.20.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
958f30503573e0e66adc529952d2f6c9ca6ecd74f39b5d64e98661e26f976bf8
BLAKE2b-256 checksum
How to use checksums
6d30681ec7fa4e85df6f73ed1c04903f9b02d6f3eceaacfa66b01fa970872fa8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

1.20 This release

1 release file

1.19

1 release file

1.18

1 release file

1.17

1 release file

1.16

1 release file

1.14

1 release file

1.12

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page