Compare json files
Say I have 2 json files.
#1
{
"ID": 1,
"Value": "A"
}
{
"ID": 2,
"Value": "B",
}
#2
{
"ID": 2,
"Value": "B"
},
{
"ID": 1,
"Value": "A",
}
I would like a compare that says these 2 files are the same.
Just because they are not in the same order they are not different.
Are there any tools that will tell me they are the same?
thanks
There's the
jq
tool you can use to print out a json with sorted keysjq -S . A.json
. Then compare the results with any text-diffing tool you like. On my linux I'd maybe doIf you are using Nodejs, apart from using `jq`, another approach is to use JSum node package
See this https://www.npmjs.com/package/jsum for more information
It is fast and does take care ordering Json object keys and checking checksum. This ensures that semantically same Jsons compare the right way