json compare utility
Likely abandoned. No release or commit for years (last release over 5 years ago).
pip install jsoncomparisonThe JSON Comparison package
This package is designed to compare two objects with a JSON-like structure and data types.
Install
pip install -U pip jsoncomparison
Usage
First you need to define two variables: expected & actual.
Think of them as the same variables that you use in tests.
Expected - the original data object that you want to see. Actual - the given data object.
Then we will transfer these objects to check and identify the difference between them:
from jsoncomparison import Compare, NO_DIFF
expected = {
"project": {
"name": "jsoncomparison",
"version": "0.1",
"license": "MIT",
"language": {
"name": "python",
"versions": [
3.5,
3.6
]
}
},
"os": "linux"
}
actual = {
"project": {
"name": "jsoncomparison",
"version": 0.1,
"license": "Apache 2.0",
"language": {
"name": "python",
"versions": [
3.6
]
}
}
}
diff = Compare().check(expected, actual)
assert diff != NO_DIFF
The check method returns a dictionary of differences between expected and actual objects:
{
"project": {
"version": {
"_message": "Types not equal. Expected: <str>, received: <float>",
"_expected": "str",
"_received": "float"
},
"license": {
"_message": "Values not equal. Expected: <MIT>, received: <Apache 2.0>",
"_expected": "MIT",
"_received": "Apache 2.0"
},
"language": {
"versions": {
"_length": {
"_message": "Lengths not equal. Expected <2>, received: <1>",
"_expected": 2,
"_received": 1
},
"_content": {
"0": {
"_message": "Value not found. Expected <3.5>",
"_expected": 3.5,
"_received": null
}
}
}
}
},
"os": {
"_message": "Key does not exists. Expected: <os>",
"_expected": "os",
"_received": null
}
}