Free online tool

Upload a file

Drop your file hereTap to choose a file

or click to browse, or paste from the clipboard

← Back to Blog

How to Compare Two JSON Files and See What Actually Changed

To compare two JSON files, parse both and compare their values path by path instead of comparing lines of text. A structural JSON diff ignores key order, indentation and number spelling such as 12.50 versus 12.5, and lists each added, removed or changed value with its location, for example /customer/email. JSON Diff does this in your browser, so nothing you paste is uploaded.

On the API example below, diff -u marks 29 lines as removed or added, while JSON Diff lists 6 real changes.

How to compare two JSON files with JSON Diff

  1. Open each file in a text editor and copy its contents. JSON Diff compares pasted text and has no file picker.
  2. Open JSON Diff, then paste the older version into Original JSON and the newer one into Updated JSON.
  3. Select Compare JSON.
  4. Read the table: Change says Added, Removed or Changed, Path locates the value, and Before and After show it on each side.
  5. Select Copy summary, or Download summary to save json-diff-summary.json. The file lists the same changes as JSON plus a truncated flag, so it can go into a bug report or pull request.

When both documents hold the same data, however they are formatted, the status line says "No differences." Otherwise, keep these points in mind:

  • Paths are JSON Pointers (RFC 6901). /items/0/sku is the sku of the first item, because positions count from 0. Inside a key, ~1 stands for a slash and ~0 for a tilde, and (root) marks a change to the top-level value itself.
  • A dash in Before or After means the value does not exist on that side. An added or removed object is listed once, at its own path, not field by field.
  • Previews are compact and capped: whitespace is dropped and long values are cut at 150 characters.
  • Editing either box clears the result, so copy or download the summary before you edit.

Why a text diff misleads on JSON

diff, Git and editor compare views work line by line, and in JSON many text differences carry no meaning. RFC 8259 defines an object as an unordered collection of name/value pairs and allows whitespace around every bracket, brace, colon and comma, so the same data can be written many ways. A JSON diff parses both sides first and keeps only differences in the data:

Difference Example Same data? JSON Diff
Key order {"a":1,"b":2} and {"b":2,"a":1} Yes No row
Indentation, line breaks Pretty-printed and minified Yes No row
Number spelling 12.50 and 12.5, 1e2 and 100 Yes No row
String escapes "\u0041da" and "Ada" Yes No row
Spaces inside a string "Ada " and "Ada" No Changed
Type 1 and "1", true and 1 No Changed
Array order [1, 2] and [2, 1] No 2 Changed rows

The order files in the next section show the effect at full size. diff -u marks 14 lines removed and 15 added, every line except the outer braces. Sorting keys first with jq -S cuts that to 6 and 7, but two on each side only turn 12.50 into 12.5, and no line carries a path. JSON Diff reports 6 rows, each a real change in the data.

Worked example: reviewing an API response change

Say an order endpoint moved to a new server and you saved one response from each. The new serializer sorts keys and indents with four spaces.

Before, saved as old.json:

{
  "id": "ord_1042",
  "status": "paid",
  "total": 42.50,
  "currency": "USD",
  "customer": {
    "id": 77,
    "email": "ada@example.com",
    "phone": "+1-555-0100"
  },
  "items": [
    {"sku": "MUG-01", "qty": 2, "price": 12.50},
    {"sku": "TEE-07", "qty": 1, "price": 17.50}
  ],
  "updated_at": "2026-11-24T09:15:00Z"
}

After, saved as new.json:

{
    "currency": "USD",
    "customer": {
        "email": "ada@example.com",
        "id": 77,
        "phone_number": "+1-555-0100"
    },
    "id": "ord_1042",
    "items": [
        {"price": 12.5, "qty": 2, "sku": "MUG-01"},
        {"price": 17.5, "qty": 1, "sku": "TEE-07"}
    ],
    "status": "shipped",
    "total": "42.50",
    "tracking_url": "https://example.com/t/1042",
    "updated_at": "2026-11-25T14:02:11Z"
}

JSON Diff returns six rows:

Change Path Before After
Changed /status "paid" "shipped"
Changed /total 42.50 "42.50"
Removed /customer/phone "+1-555-0100" —
Added /customer/phone_number — "+1-555-0100"
Changed /updated_at "2026-11-24T09:15:00Z" "2026-11-25T14:02:11Z"
Added /tracking_url — "https://example.com/t/1042"

Read each row the way an API client would:

  • /total changed type: the number 42.50 became the string "42.50". Code that adds totals or checks types breaks although the text looks the same, so treat type changes as breaking.
  • A Removed and an Added row with the same value is a rename. Clients reading customer.phone now get nothing.
  • /status is an ordinary data change, while /updated_at is noise that changes on every request; Troubleshooting below shows how to remove it first.
  • /tracking_url is new. Additions rarely break clients unless they reject unknown fields.

The new key order, the four-space indentation and the prices written as 12.5 produce no rows. If a changed value is an epoch number that gained three digits, the API probably switched from seconds to milliseconds: the Unix Timestamp Converter reads 10 digits as seconds and 13 as milliseconds, and the Unix timestamp guide explains the units. When a response changes shape, regenerate client types from the new sample with JSON to TypeScript.

How arrays are compared, and how to stop the shift

JSON arrays are ordered, so JSON Diff compares them by position: item 0 with item 0, item 1 with item 1. That is right for steps, rankings and coordinates, but in a list of records one insertion near the start shifts every later item. Here a cart gains a pin badge at the front:

{"items": [{"sku": "MUG-01", "qty": 2}, {"sku": "TEE-07", "qty": 1}, {"sku": "CAP-03", "qty": 1}]}
{"items": [{"sku": "PIN-09", "qty": 3}, {"sku": "MUG-01", "qty": 2}, {"sku": "TEE-07", "qty": 1}, {"sku": "CAP-03", "qty": 1}]}
Both files prepared with Rows What JSON Diff shows
Nothing 6 Five Changed rows, then CAP-03 Added at /items/3
sort_by(.sku) 3 PIN-09 replaces TEE-07 at /items/2, TEE-07 Added at /items/3
INDEX(.sku) 1 Added at /items/PIN-09
jq '.items |= sort_by(.sku)' cart.json   # sort records by SKU
jq '.items |= INDEX(.sku)' cart.json     # key records by SKU

Sorting fixes a pure reorder: the same three items in another order compare as "No differences." after sort_by. It cannot fix an insertion, because everything after the new item still moves. INDEX(.sku) turns the array into an object keyed by SKU, and objects are matched by key, so each item is compared with the item that has the same SKU, wherever it sits. The key must be unique and present in every item: INDEX keeps only the last of two items with the same key and files items without one under "null".

For plain lists where order means nothing, such as tags or permissions, jq '.tags |= sort' is enough. Run it on both files before comparing.

Compare JSON files on the command line and in code

jq is a free command-line JSON processor. These commands use the order files above, and the outputs come from jq 1.7.1.

A yes or no answer with jq

jq -n --slurpfile a old.json --slurpfile b new.json '$a == $b'

This prints false for the order files. jq's == ignores key order in objects and compares numbers by value, so 12.50 equals 12.5, while array order still counts. Add -e and jq exits with status 1 when the answer is false, which fails a CI step.

A line diff with sorted keys

diff -u <(jq -S . old.json) <(jq -S . new.json)

-S sorts every object's keys and re-indents the output, so key order and formatting drop out. Arrays still compare by position, and because jq 1.7 and later keep numbers as written, 12.50 and 12.5 still differ. The <( ) syntax works in bash and zsh, including Git Bash and WSL on Windows. Without jq, python3 -m json.tool --sort-keys gives a similar sorted copy that rewrites 12.50 as 12.5 but silently keeps only the last of a repeated key.

For one line per value with its path, diff jq's stream form:

diff <(jq -c 'tostream | select(length == 2)' old.json | sort) \
     <(jq -c 'tostream | select(length == 2)' new.json | sort)
4c4
< [["customer","phone"],"+1-555-0100"]
---
> [["customer","phone_number"],"+1-555-0100"]

That is the first of four blocks; the price lines show up too, for the same number-spelling reason.

Make git diff ignore key order

echo '*.json diff=json' >> .gitattributes
git config diff.json.textconv "jq -S ."

Git then runs JSON files through jq -S . before git diff, git log -p and git show display them, as the gitattributes documentation describes. Stored files are untouched, and the config line applies only to your clone. In VS Code, select two files and choose Compare Selected from the context menu (user interface docs); it is a line diff too, so sort keys first.

Diff JSON objects in Python and JavaScript

Both snippets print False or false for the order files. They ignore key order and compare arrays by position.

import json

with open("old.json", encoding="utf-8") as f1, open("new.json", encoding="utf-8") as f2:
    print(json.load(f1) == json.load(f2))
const { readFileSync } = require("node:fs");
const { isDeepStrictEqual } = require("node:util");

const read = (file) => JSON.parse(readFileSync(file, "utf8"));
console.log(isDeepStrictEqual(read("old.json"), read("new.json")));

Parsing into native types changes what counts as equal. Each method gave these results on the pairs shown:

Pair JSON Diff jq == Python == Node.js
true and 1 Changed Not equal Equal Not equal
12.50 and 12.5 No row Equal Equal Equal
9007199254740993 and …992 Changed Not equal Not equal Equal
{"s":1,"s":2} and {"s":2} Error Equal Equal Equal

Python treats True as equal to 1 because booleans are a subtype of integers, so a flag that turns into a number slips through. In Node.js, JSON.parse stores numbers as 64-bit floats, so integers above 2⁵³ − 1 can collapse into one value (the guide to invalid JSON explains why), and isDeepStrictEqual then reports two equal objects. All three keep only the last of a repeated key. JSON Diff compares numbers as exact decimals and refuses repeated keys instead.

To list the changes in code, use a diff library such as DeepDiff in Python or jsondiffpatch in JavaScript, which report added, removed and changed values with their paths.

Troubleshooting

"Invalid JSON token" or "Expected a quoted property name"

Both boxes need strict JSON, and the message names the side, Original or Updated, with the line and column of the first problem. Comments, trailing commas, single quotes and objects printed by JavaScript or Python are the usual causes. An error at line 1, column 1 often means a byte order mark or text before the first brace. Check the document in the JSON Formatter & Validator, and see the guide to fixing invalid JSON for each error.

"Duplicate object key"

JSON Diff refuses an object that repeats a key, because parsers disagree about which value counts and RFC 8259 calls the result unpredictable. Remove or rename the key named in the message.

Every array item shows as Changed

An item was inserted or removed near the start, so everything after it shifted. Key the records by a unique field with INDEX, as shown above.

Timestamps and request IDs always differ

Delete those fields from both files before comparing:

jq 'del(.updated_at)' old.json
jq 'walk(if type == "object" then del(.updated_at, .request_id) else . end)' old.json

The first removes a top-level field, the second removes the named fields at any depth. Keep the list short, because every deleted field is one you no longer check.

"Unexpected content after the root value"

Each box takes one JSON value, and a JSON Lines log holds one per line. Wrap the lines into an array with jq -s . log.jsonl, or compare one line at a time.

Too large, or "Summary limit reached"

Each document can be up to 250,000 characters and 128 levels deep, and indentation counts toward the characters, so minify big files first in the JSON Formatter or with jq -c .. A comparison stops at 1,000 differences: the status line says the summary limit was reached, and the summary sets truncated to true. Compare one section at a time, such as the output of jq '.items' old.json.

Frequently asked questions

Can I compare JSON online without uploading it?

Yes. JSON Diff parses, compares and builds the summary file in the page, so nothing is sent to a server. To keep data off the web entirely, use the jq or Python checks above on your own machine.

Does key order matter when comparing JSON?

Not in objects. RFC 8259 defines an object as unordered, so {"a":1,"b":2} and {"b":2,"a":1} hold the same data, and JSON Diff, jq, Python and Node.js all treat them as equal. Order does matter inside arrays.

What is the difference between a JSON diff and a text diff?

A text diff compares lines, so reformatting, reordered keys and 12.5 written as 12.50 all count as changes. A JSON diff parses both documents and compares values by path, so only data changes remain, each with its location.

How do I compare JSON arrays regardless of order?

Prepare both files first: jq '.tags |= sort' for plain values, or jq '.items |= INDEX(.id)' to match records by a unique field. JSON Diff always compares arrays by position and does not detect moved items.

How do I diff two JSON objects in Python or JavaScript?

For a yes or no answer, compare the loaded objects with == in Python or util.isDeepStrictEqual in Node.js. Both ignore key order, but Python treats true as equal to 1, and JavaScript loses digits in integers above 2⁵³ − 1. For a list of what changed, use JSON Diff, or a library such as DeepDiff (Python) or jsondiffpatch (JavaScript).