ยป npm install json-diff-kit
Is there a library that allows to easily do diffchecks between two json?
windows - Offline JSON diff tool - Software Recommendations Stack Exchange
Javascript json diff patch html viewer doesn't match demo - Stack Overflow
Diff two large JSON array or objects
I am wondering if there's something that allows you to easily display differences between two json like on diffchecker.com. Is there a library that allows you to easily do that?
Use jq to first sort all keys. Then diff to do the diffing:
jq -S . A.json > A-sorted.json
jq -S . B.json > B-sorted.json
diff A-sorted.json B-sorted.json
The above example is for Linux but both jq and diff is available for Windows.
It seems Windows has an alternative diff tool called fc, perhaps this could be used instead of diff.
QT JSON Diff [Github] might be for you:
- They have a Windows build (see "Win64" in the releases)
- It is gratis, MIT license
- It works offline, as an EXE which runs locally
- can sort objects inside arrays so that order matters less
I have a Python lambda function downloading a large excel file and converting it to JSON.
This file will be downloaded at least once a day (as the data can change)
I need to push the changed/updated data to an API.
Is there a way for me to compare two JSON files and output the diff?
It would be perfect if it would output multiple arrays of objects.
1 array of objects that have changed (I donโt care what has changed, just need to know that it has)
1 array of removed/deleted objects.
If I understand the question correctly, the following should do the job. I'll assume you have access to jq 1.5, which includes the filter walk/1 (if that is not the case, it's easy to supplement the file below with the definition, which can be found on the web, e.g. the src/builtin.jq file), and that you have a reasonably modern Mac or Linux-like shell.
(1) Create a file called (let's say) jq-diff.jq with these two lines:
def sortKeys: to_entries | sort | from_entries;
walk( if type == "object" then sortKeys else . end )
(2) Assuming the two files with JSON entities in them are FILE1 and FILE2, then run one of the following commands, depending on whether you want the JSON entities within each file to be sorted:
diff <(jq -cf jq-diff.jq FILE1 | sort) <(jq -cf jq-diff.jq FILE2 | sort)
# OR:
diff <(jq -cf jq-diff.jq FILE1) <(jq -cf jq-diff.jq FILE2)
Brief explanation:
The role of jq here is to sort the keys in the objects (without sorting the arrays) and to print them in a standard way, one per line (courtesy of the -c option).
You can use the -s flag to slurp your newline-separated JSON objects into a JSON array containing them, thus making them eligible for comparison with json-diff.