json.cihat.dev

JSON diff: compare two JSON files

Paste two JSON documents to compare them online and see what changed, value by value, with the path to each difference. Key order and spacing are ignored, and nothing is uploaded.

How to use it

  1. Paste the original JSON on the left and the changed one on the right, or open a file on each side. An example pair is loaded.
  2. Read the summary: how many values were added, removed and changed.
  3. The table lists each difference with its path, such as $.hours.sat, and the value before and after.
  4. Switch to Line by line to see both documents formatted the same way, with removed lines marked − and added lines marked +.

Why a text diff is not enough for JSON

Two JSON files can hold the same data and still differ on every line: keys in another order, other indentation, everything on one line. A plain text diff then shows the whole file as changed. RFC 8259 defines an object as an unordered collection and lets whitespace sit around any bracket, comma or colon, so none of those differences change the data. This tool reads both documents first and compares the data: objects key by key whatever their order, arrays position by position, and numbers by value.

A worked example

The example pair loaded above is a shop record before and after an edit. The second file lists hours in another order and is indented differently; neither counts. What the tool reports:

PathChangeBeforeAfter
$.nameChanged"Harbour Books""Harbour Books & Maps"
$.hours.satChanged"10-14""10-16"
$.hours.sunAdded"11-15"
$.tags[2]Added"charts"
$.phoneRemoved"+44 1326 000000"

Reading the result

Added is a key or array item only in the changed document. Removed is only in the original. Changed is the same path with another value, and Type changed means, for example, that the number 42 became the string "42", a common sign of a serializer change.

Arrays are compared by position, because RFC 8259 defines an array as an ordered sequence. When an item is inserted at the start of an array, every item after it counts as changed. If your array is really a set, such as a list of tags, sort it the same way on both sides first.

Numbers and strings

Numbers are compared by exact decimal value: 1.0 equals 1 and 1e3 equals 1000. Long integers are compared digit by digit, so 12345678901234567890 and 12345678901234567891 are reported as different. A comparison done through JSON.parse would call them equal, because both round to the same 64-bit number. Strings must match exactly, including case and trailing spaces.

The Line by line view formats both documents with 2-space indentation and keys sorted A to Z, then diffs the text. That makes it useful for a code review, but there 1.0 and 1 still show as different lines. Trust the path list for meaning.

Diff, JSON Patch and Merge Patch

Two standards describe changes to JSON as JSON. JSON Patch (RFC 6902) is a list of operations, namely add, remove, replace, move, copy and test, each pointing at a location written as a JSON Pointer (RFC 6901), such as /hours/sat. JSON Merge Patch (RFC 7396) is a partial document where a null value removes the key. The path list here maps directly onto the first: an added row is an add, a removed row a remove, a changed row a replace.

Before comparing, check that both files are valid with the JSON formatter. To explore a large document first, open it in the JSON viewer. For configuration files, convert YAML with JSON to YAML and compare the JSON.

Questions people ask

Are my files uploaded?

No. Both documents are compared in your browser; nothing is sent to a server.

Does key order count as a difference?

No. JSON objects have no meaningful key order, so it is ignored. Array order does count.

How do I compare two JSON files without caring about array order?

Sort both arrays the same way first, for example by an id field, then compare. This tool compares arrays by position, as RFC 8259 treats them as ordered.

Can I compare large files?

Yes, up to 64 MB each. Files above 200 KB are parsed in a background thread; the table lists up to 2,000 differences.

What if one side is invalid?

The tool says which side, on which line and column, and what is wrong. The JSON formatter on this site can repair common mistakes.

Can it produce a JSON Patch?

Not as a file. Each row of the path list corresponds to one JSON Patch operation (add, remove or replace), so the list tells you what a patch would contain.