Skip to content
HandyKit

JSON Compare

Paste two JSON documents to see exactly what changed: added, removed and changed values, each with its path. Key order and formatting are ignored.

Runs in your browser. Your input is never uploaded or stored.

These are examples. Paste your own JSON into each side.

Differences

5 differences: 3 added, 1 removed, 1 changed.

ChangePathOriginalChanged
Changed$.version"1.0.0""1.1.0"
Removed$.privatetrue—
Added$.scripts.test—"vitest"
Added$.keywords[2]—"privacy"
Added$.license—"MIT"

What a structural comparison is

A text diff compares lines of characters. That suits source code, but it is noisy for JSON. Reformat a file, reorder two keys or change the indentation, and a text diff flags lines that mean exactly the same thing.

A structural (semantic) comparison parses both documents first and then compares the values they contain. Whitespace, line breaks and key order drop out, so you see only real changes: a value that was added, removed or changed.

How to use JSON Compare

  1. Paste your first document into Original JSON.
  2. Paste the second document into Changed JSON.
  3. Read the summary line and the table below the editors. The result updates as you type.
  4. Select Copy as text if you want a plain report to paste into a ticket or message.

The tool opens with an example pair of package.json-like documents. Pasting replaces them. Swap sides exchanges the two editors, so additions become removals and the other way round. Clear empties the editors.

Everything runs in your browser. Nothing is uploaded.

If either document is not valid JSON, the tool shows the syntax error with its line and column, and tells you which side it is in.

Reading the results

The summary line gives the totals, for example 3 differences: 1 added, 1 removed, 1 changed. The table below has four columns: Change (Added, Removed or Changed), Path, Original and Changed. The tool lists up to 2000 differences.

Copy as text produces a plain report with one line per difference:

+ $.license: "MIT"
- $.private: true
~ $.version: "1.0.0" → "1.1.0"

Paths use JSONPath. Some examples:

  • $.scripts.test is the test key inside scripts.
  • $.keywords[2] is the third item of the keywords array.
  • $["key with spaces"] is a key that cannot be written with dot notation.

To use a path in jq, replace the leading $ with a dot. $.scripts.test becomes .scripts.test.

Objects are compared by key, so key order never counts as a difference. A value whose type changes, such as the string "1" against the number 1, or {} against [], is reported as changed.

How arrays are compared

Arrays are compared by position. Index 0 is matched with index 0, index 1 with index 1, and so on. Extra items at the end show as added or removed.

This means an insert at the start of an array shifts everything after it. Take these two arrays:

["b", "c"]
["a", "b", "c"]

The comparison reports index 0 as changed from "b" to "a", index 1 as changed from "c" to "b", and a new item at index 2. You inserted one item, but the tool shows three differences.

The tool does not detect moved items, and it does not treat arrays as sets.

Numbers and strings

Numbers are compared by exact decimal value:

  • 1, 1.0 and 1e0 are equal.
  • 0.5 and 5e-1 are equal.
  • 1.00000000000000001 and 1 are different. JavaScript would round both to the same double, but this tool does not.
  • Big integers keep every digit.

Strings are compared by their decoded value. The escaped form "A" equals "A".

Comparing JSON in code

To get a similar result in a shell, sort the keys with jq and then run an ordinary text diff:

diff <(jq -S . a.json) <(jq -S . b.json)

The -S option sorts object keys, so key order does not matter. The comparison afterwards is still line by line, and it reports lines rather than paths.

In JavaScript, a deep-equal function tells you whether two values match. Node’s util.isDeepStrictEqual is one example:

import { isDeepStrictEqual } from 'node:util';

const a = JSON.parse(originalText);
const b = JSON.parse(changedText);

console.log(isDeepStrictEqual(a, b)); // true or false

It returns only true or false. It does not tell you what differs or where. Note too that JSON.parse turns numbers into doubles, so very precise decimals and big integers can lose digits before the comparison begins.

Frequently asked questions

Does key order matter?

No. Objects are compared by key, so two objects with the same keys and values are equal whatever order the keys appear in. Array order does matter, because arrays are compared by position.

Why does inserting one array item show so many changes?

Arrays are compared by position, so index 0 is matched with index 0, index 1 with index 1, and so on. If you insert an item at the start, every later item sits at a new index and is reported as changed, with one extra item added at the end. The tool does not detect moved items or treat arrays as sets.

Are 1 and 1.0 different?

No. Numbers are compared by exact decimal value, so 1, 1.0 and 1e0 are equal, and so are 0.5 and 5e-1. However, 1.00000000000000001 and 1 are different, because the tool does not round to a double the way JavaScript does. Big integers keep every digit.

Is my data uploaded?

No. The comparison runs in your browser as you type, and nothing is sent to a server.

Can I compare large files?

You can paste large documents, because the comparison happens in your browser. Very large files may be slow, since the result is recalculated as you type. The table lists up to 2000 differences.

Can I ignore some fields?

No, the tool has no option to ignore fields. Remove the fields you do not care about from both documents before you compare them.

Guides

  • · 2 min read

    How to Compare Two JSON Files

    Find what changed between two JSON documents, ignoring key order and formatting. A worked example, how to read JSONPath, and how arrays and numbers compare.

  • · 2 min read

    Minify JSON: What It Does and When to Use It

    What minifying JSON removes, what it never changes, when it is worth doing and when it is not, and why sorting keys gives stable output you can compare or hash.