JSON Diff – Compare Two JSON Files

Paste two JSON documents to see exactly what changed between them. Unlike a text diff, the comparison ignores formatting and key order and reports each difference by its path, such as $.limits.storage, with the value before and after. Arrays of simple values can be compared without regard to order, and the result can be exported as a JSON Patch (RFC 6902) that turns the first document into the second. Everything runs locally.

Original (A)

160 characters

Changed (B)

181 characters

Result

6 differences: 2 added, 1 removed, 3 changed.

PathChangeIn AIn B
$.priceChanged912
$.features[0]Changed"5 projects""10 projects"
$.features[2]Added"API access"
$.limits.storageChanged1020
$.betaRemovedtrue
$.currencyAdded"USD"
JSON Patch (RFC 6902) that turns A into B
[
  {
    "op": "replace",
    "path": "/price",
    "value": 12
  },
  {
    "op": "replace",
    "path": "/features/0",
    "value": "10 projects"
  },
  {
    "op": "replace",
    "path": "/limits/storage",
    "value": 20
  },
  {
    "op": "remove",
    "path": "/beta"
  },
  {
    "op": "add",
    "path": "/features/2",
    "value": "API access"
  },
  {
    "op": "add",
    "path": "/currency",
    "value": "USD"
  }
]

Runs entirely in your browser. Nothing you paste or open here is uploaded or stored.

How to use the JSON diff tool

  1. Paste the original document into Original (A) and the newer one into Changed (B).
  2. Read the summary: the total number of differences, split into added, removed and changed.
  3. Scan the table. Each row shows the path, the kind of change and the values in A and B.
  4. Turn on “ignore order” if your arrays are unordered lists of simple values.
  5. Copy the JSON Patch if you need a machine-readable list of changes.

Swap A and B reverses the comparison, which turns additions into removals.

How the comparison works

Both documents are parsed with a strict JSON parser (comments and trailing commas are tolerated, as in the formatter). The comparison then walks both trees together:

  • objects are compared key by key, so key order never matters;
  • arrays are compared index by index (or as multisets when order is ignored);
  • values are compared by type and value, so 1 and "1" are reported as a type change, not a simple change.

Paths use JSONPath-style notation ($.users[2].email), with unusual keys quoted ($["content-type"]). The patch uses JSON Pointer (/users/2/email), where / inside a key becomes ~1 and ~ becomes ~0.

Worked examples

Example 1: a pricing change

Load the sample. The price changes from 9 to 12, a feature is renamed and another added, storage doubles, beta is removed and currency is added. Six differences appear, each with its exact path, which is easier to review than a reformatted text diff.

Example 2: API response regression

Save a known-good response as A and today’s response as B. A type change from number to string ("price": "12.00") stands out immediately. That kind of change often breaks clients even though the value looks the same.

Example 3: tags in a different order

Compare {"tags": ["red", "blue"]} with {"tags": ["blue", "red"]}. By default two changes are shown, because positions 0 and 1 differ. With ignore order on, there are no differences.

Applying the patch

The generated patch lists replacements first, then removals (array items from the highest index down so earlier positions stay valid), then additions. Libraries such as fast-json-patch (JavaScript), jsonpatch (Python) and most API frameworks can apply it. When order is ignored, changes have no single position, so no patch is offered.

Common mistakes

  • Comparing formatted text. Whitespace differences aren’t data changes; compare parsed JSON instead.
  • Ignoring order on arrays of objects. Order is only ignored for simple values, because object matching needs a key.
  • Treating type changes as harmless. "5" and 5 behave differently in code.
  • Huge arrays shifted by one item. An insertion at the start shows every later index as changed. Sort both arrays by a stable key first.

Frequently asked questions

How is this different from a normal text diff?

A text diff compares lines, so reformatting or reordering keys shows up as changes even when the data is identical. This tool parses both documents and compares values, so only real data changes are reported.

What is a JSON Patch?

JSON Patch (RFC 6902) is a standard list of operations (add, remove, replace) addressed with JSON Pointer paths. Applying the generated patch to document A produces document B, which is useful for PATCH requests and change logs.

How are arrays compared?

By default, item by item at each position, because order usually matters in JSON. If your arrays are sets of simple values, such as tags, turn on “ignore order” to compare them as collections instead.

Can I compare large files?

Yes, up to several megabytes, depending on your device. The comparison runs in your browser and lists the first 2,000 differences.

Does key order matter in the comparison?

No. JSON objects are unordered, so the same keys in a different order count as equal. Array order does matter, because arrays are ordered lists.

Sources