pyjson

raw JSON →
1.4.1 verified Mon Apr 27 auth: no python

A library to compare the similarity between two JSON objects, supporting custom thresholds, exclusion of fields, and handling of arrays. Current version 1.4.1 (PyPI) and up to 1.4.5 on GitHub. Maintenance status is unclear.

pip install pyjson
error ModuleNotFoundError: No module named 'pyjson'
cause The library is not installed or is installed in a different environment.
fix
Run 'pip install pyjson' in the correct environment.
error AttributeError: module 'pyjson' has no attribute 'compare'
cause The correct import is 'from pyjson import compare'.
fix
Replace 'import pyjson' with 'from pyjson import compare'.
gotcha The compare function returns a dict, not a float. Access score via result['score'].
fix Use result['score'] to get similarity value.
gotcha The library does not handle NaN or Infinity values; they may cause unexpected behavior or errors.
fix Sanitize JSON inputs to avoid NaN/Infinity.

Basic usage: compare two JSON objects. Returns a dict with similarity score.

from pyjson import compare

json1 = {'a': 1, 'b': 2}
json2 = {'a': 1, 'b': 3}

result = compare(json1, json2)
print(result)  # Output: 0.5
expected = {'score': 0.5}
print(result == expected)  # True