JSON Diff

Compare two JSON documents, ignoring key order and formatting.

About JSON Diff

A JSON diff tool compares two JSON documents and shows what changed, ignoring key order and formatting. Added and removed lines are highlighted as you type.

How to use

  1. Paste or load the first document on the left and the second on the right. Each side reports its own parse error with a line number until it is valid JSON.
  2. Leave "Ignore key order" on so that {"a": 1, "b": 2} and {"b": 2, "a": 1} count as equal. Tick "Ignore array order" when arrays are sets rather than sequences.
  3. Read the diff: lines beginning with - exist only on the left, lines beginning with + only on the right. Unchanged runs are folded unless "Show unchanged lines" is ticked.
  4. Copy or download the diff as a .patch file.

What it does

  • Parses both sides, sorts object keys recursively (when "Ignore key order" is on) and pretty-prints each with two-space indentation. Only then are the two texts compared line by line, so indentation, spacing and key order never show up as differences.
  • Numbers are compared by value: 1.0 and 1 are the same, as are 1e2 and 100. Integers above 2^53 lose precision in the browser, so differences in those digits are not detected.
  • "Ignore array order" sorts the items of every array by their JSON text before comparing, so [1, 2] equals [2, 1]. Off by default because order usually matters in arrays.
  • Reports "Identical after normalisation" when nothing differs, otherwise the number of lines added and removed. The patch is a plain line diff, not a JSON Patch (RFC 6902) document.
  • Both sides must parse; the tool does not compare JSON with trailing commas or comments.

Example

Left:  {"name": "xutil", "tools": 42, "tags": ["a", "b"]}
Right: {"tags": ["a", "b"], "tools": 43, "name": "xutil"}

   "name": "xutil",
   "tags": [
     "a",
     "b"
   ],
-  "tools": 42
+  "tools": 43

Privacy

Both documents are compared in the browser. No request is made, and nothing is stored.

Frequently asked questions

How do I compare two JSON files ignoring the order of keys?
Parse both files, sort every object's keys recursively, pretty-print them with the same indentation and diff the results. That is what this tool does with "Ignore key order" on, so two documents that differ only in key order show as identical.
Does the order of elements in a JSON array matter?
Yes. JSON arrays are ordered, so [1, 2] and [2, 1] are different values. When an array is used as an unordered set, tick "Ignore array order" and the items are sorted before the comparison.
What is the difference between a JSON diff and a JSON Patch?
A diff shows the lines that differ for a person to read. A JSON Patch (RFC 6902) is a machine-readable list of add, remove and replace operations that turns one document into the other. This tool produces a line diff.
Why does the diff treat 1.0 and 1 as equal?
JSON has one number type and the two spellings denote the same value, so after parsing there is no difference left to show. The same applies to 1e2 and 100.