JSON Diff

Real differences, with the path to each.

Real differences, with the path to each.

How to use it

  1. Paste both documents. Formatting and key order do not matter.
  2. Read the differences. Each one shows the path and both values.
  3. Check for absent. A key on one side only is reported as absent on the other.

When you would use this

Comparing two JSON documents with a text diff produces a report full of things that are not differences. Key order is the main one. Two serialisers emit the same object with the fields in a different sequence, and a line based diff reports every one of them as a change. Reindent one of the files and the whole thing is different. In both cases the two documents hold exactly the same value. This walks the structure instead. Only genuine differences appear, each with the path to it, so a report of two hundred lines becomes a report of two. Arrays are compared by position rather than by content, which is deliberate. An array's order is part of its value in JSON, so an inserted element really does change every index after it, and pretending otherwise would hide a real difference. Null and absent are distinguished. A key that is present and null is a different state from a key that is not there, and conflating them hides a class of bug that is hard to find any other way.

Questions

Why not just use a text diff?
Because a text diff reports reordered keys and reindented blocks as changes, and in JSON neither is a change: the two documents hold the same value. Walking the structure means only real differences appear, which is usually the difference between a report with two lines in it and one with two hundred.
How are arrays compared?
By position, so an inserted element at the start shows every subsequent index as different. That is honest for JSON: an array's order is part of its value, and treating a shifted array as unchanged would hide a real difference.
Does it tell null and missing apart?
Yes. A key present with a null value and a key that is not there are different states, and conflating them hides a real class of bug. Null is reported as null and a missing key as absent.