Skip to main content Compare json files : r/json

Get the Reddit app

Scan this QR code to download the app now
Or check it out in the app stores
Go to json

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

Sort by:
Best
Open comment sort options

There's the jq tool you can use to print out a json with sorted keys jq -S . A.json. Then compare the results with any text-diffing tool you like. On my linux I'd maybe do

diff <(jq -S . A.json) <(jq -S . B.json)

If 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