How to compare two JSON files: structural diffs that ignore key order and whitespace
Compare JSON by structure: objects by key, arrays by position, numbers by value. Whitespace and key order should never count as changes, and every difference should come with its path.
Comparing JSON as plain text works badly. Reformat a file, let a serializer sort its keys, or move one property, and a line diff lights up the whole document even though no value changed. A structural diff reads both documents first and compares the values, so it reports what changed and where, with a path like $.items[3].price for each difference.
By TechCompare · Updated
How this is calculated
JSON objects are unordered by definition, so {"a":1,"b":2} and {"b":2,"a":1} hold the same data. Arrays are ordered, so [1,2] and [2,1] are different, unless the array is really a set, like a list of tags. A good diff lets you pick. Arrays need care in another way too. Insert one item at the start of a list and a naive comparison sees every later index as changed. Lining the arrays up with a longest common subsequence fixes that, so the insert shows as one addition. Numbers need a rule as well. 1.0 and 1 are the same value written two ways, while 9007199254740993 and 9007199254740992 are different values that JavaScript happens to read as the same double. A diff that runs JSON.parse first can call those equal, which is exactly the wrong answer for IDs. Repeated keys are the last trap. When an object has the same key twice, parsers disagree on which copy wins, so an honest diff refuses to guess.
Verdict
Use a structural diff to review API changes, config edits and fixtures. Keep array order on for lists where position matters, like steps or rankings, and turn it off for sets like tags or permissions. Treat a repeated key as a bug to fix before comparing. When a diff says two documents match, it should mean every key and every exact value matches, not just that the formatted text looked similar.
More JSON scenarios
Related guides
Frequently asked questions
Why does my text diff show changes when the JSON is the same?
Should a JSON diff ignore array order?
Are 1.0 and 1 different in JSON?
Related tools
Unix Timestamp
Convert between Unix timestamps and human-readable dates.
Use tool ➜CHMOD Configurator
Calculate Linux file permissions using checkboxes or octal numbers, then view the matching symbolic notation.
Use tool ➜Text Encoding Converter
Convert between Text, Base64, Binary, Hexadecimal, and Decimal formats.
Use tool ➜