I have two JSON responses from the same platform with keys in a different order. How can I compare them to see what actually changed?
Format both in the JSON formatter with the same indent and 'Sort keys alphabetically' ticked, so keys at every level appear in one fixed order while array items keep theirs. Then paste the two results into the text compare tool, and only real differences in values or structure remain.
Why a direct comparison fails
In JSON the order of keys inside an object does not change the meaning: {"a":1,"b":2} and {"b":2,"a":1} are the same data. But systems do not always keep to one order, so the same system can return an order one way today and another way tomorrow. A compare tool works line by line, sees every line out of place as a change, and buries you in differences that are not there.
Example: an order before and after shipping
The first response, with the order paid:
{"status":"paid","id":55,"items":[{"sku":"B","qty":1},{"qty":2,"sku":"A"}]}
The second response after shipping, with a different key order at every level:
{"id":55,"status":"shipped","items":[{"qty":1,"sku":"B"},{"sku":"A","qty":2}]}
Formatted with 2 spaces and sorted keys, each becomes 14 lines in the same order: id, then items, then status, and inside each item qty then sku. The two results match line for line except one: status goes from paid to shipped. That is the only real change.
Notice the two array items kept their order, B first and then A; they were not sorted. Key sorting applies to object keys only, because the order of array items is part of the data itself.
The steps
- Open the JSON formatter and validator and paste the first response.
- Choose 'Format' with 2 spaces, tick 'Sort keys alphabetically', and copy the output.
- Clear the input, paste the second response with exactly the same settings, and copy the output.
- Open Text comparison, paste the two outputs into its two boxes, and compare by lines.
- Read the marked lines: they are the real differences in values or in which keys exist.
Mistakes that spoil the comparison
- Different indents: 2 spaces for one text and 4 for the other makes every line differ. Use the same setting.
- Forgetting to sort keys in one of the two.
- An array whose items really did change order: that is a genuine difference in the data, the comparison will show it, and the tool will not hide it because it never sorts arrays.
- A duplicate key in one response: only the last value survives formatting, and the tool shows a duplicate-key warning. Pay attention to it before you trust the comparison.
Instead of copying from the output box you can download each result as a file and keep it, if you want to compare more responses later.
Common questions
What order are keys sorted in?
By character code, so capitals come before lowercase and Arabic keys after Latin ones. What matters is that the order is the same in both responses.
Does sorting change the data?
No. It is the same data with a different key order; array items are never touched.
Can I compare inside the formatter itself?
No, the formatter does not compare. It prepares the two texts, and the comparison happens in the text compare tool.
