If your shell supports process substitution (Bash-style follows, see docs):
diff <(jq --sort-keys . A.json) <(jq --sort-keys . B.json)
Objects key order will be ignored, but array order will still matter. It is possible to work-around that, if desired, by sorting array values in some other way, or making them set-like (e.g. ["foo", "bar"] → {"foo": null, "bar": null}; this will also remove duplicates).
Alternatively, substitute diff for some other comparator, e.g. cmp, colordiff, or vimdiff, depending on your needs. If all you want is a yes or no answer, consider using cmp and passing --compact-output to jq to not format the output for a potential small performance increase.
Jd – JSON Diff and Patch
diff - Using jq or alternative command line tools to compare JSON files - Stack Overflow
python 3.x - Diff json files and write changes - Stack Overflow
Automate JSON compare
If your shell supports process substitution (Bash-style follows, see docs):
diff <(jq --sort-keys . A.json) <(jq --sort-keys . B.json)
Objects key order will be ignored, but array order will still matter. It is possible to work-around that, if desired, by sorting array values in some other way, or making them set-like (e.g. ["foo", "bar"] → {"foo": null, "bar": null}; this will also remove duplicates).
Alternatively, substitute diff for some other comparator, e.g. cmp, colordiff, or vimdiff, depending on your needs. If all you want is a yes or no answer, consider using cmp and passing --compact-output to jq to not format the output for a potential small performance increase.
Use jd with the -set option:
No output means no difference.
$ jd -set A.json B.json
Differences are shown as an @ path and + or -.
$ jd -set A.json C.json
@ ["People",{}]
+ "Carla"
The output diffs can also be used as patch files with the -p option.
$ jd -set -o patch A.json C.json; jd -set -p patch B.json
{"City":"Boston","People":["John","Carla","Bryan"],"State":"MA"}
https://github.com/josephburnett/jd#command-line-usage
» pip install jsondiff
Hey all,
So I’m taking over a role for a coworker managing content for our site in AEM. We have three AEM environments: we make changes in the lower one and push it to the middle environment to test it before pushing the middle to production.
Part of the testing involves comparing JSONs between the lower and middle environments to ensure they match. Right now, we do this in Notepad++ by copying the JSON code from each environment and doing a simple compare. This is incredibly time consuming so I am looking to automate the process. Something as simple as, here’s a list of lower/middle environment JSONs side by side; compare these and return if they match or not.
I typically work in Excel and code in VBA since it’s a program everyone in the enterprise has so there’s no special access required. In researching I’ve noticed Python makes JSON compare pretty easy but I haven’t really seen any automated JSON compare code. Could anyone point me in the right direction?
Thanks all!