velkaro.Runs in your browser

JSON field notes · 01

How to compare JSON files and read the differences

A structural JSON comparison tells you which values changed. Indentation and object key order do not create differences; array order and value types do.

Compare a plan update

Download before.json and after.json. Open them in the two editors (or drop them on the editors). Clear the Match array items by field so arrays are compared by position.

Before

{
  "plan": "starter",
  "limits": {"seats": 2},
  "tags": ["red", "blue"],
  "deprecated": true
}

After

{
  "plan": "pro",
  "limits": {"seats": 5},
  "tags": ["blue", "red"],
  "enabled": true
}

Expected: 6 changes by position; 4 changes with “Ignore array order” selected.

PathChangeBefore → After
$["plan"]Changedstarter → pro
$["limits"]["seats"]Changed2 → 5
$["tags"][0]Changedred → blue
$["tags"][1]Changedblue → red
$["deprecated"]Removedtrue → absent
$["enabled"]Addedabsent → true

Open the JSON comparison tool

Choose what array order means

Keep positional mode for ordered steps, rankings and time series. Use “Ignore array order” when arrays are collections and position has no meaning. The setting applies to nested arrays too. Comparing JSON while ignoring array order walks through all four option combinations on one document.

With order ignored, a different collection is reported as one whole-array change. Duplicate items still count: [1,1,2] differs from [1,2].

JSON values keep their types

1 and "1" differ, and the report labels it as a type change. A missing property and a property containing null also differ. Paths use bracket notation so dots inside property names stay unambiguous.

Match array items by id

In API responses, deleting one item from the middle of a list shifts every later item. By position, each shifted item looks changed. Enter the identifying property in Match array items by and items are paired by that value instead.

Before

{"users": [
  {"id": 1, "name": "Ana"},
  {"id": 2, "name": "Ben"},
  {"id": 3, "name": "Cy"}
]}

After

{"users": [
  {"id": 1, "name": "Ana"},
  {"id": 3, "name": "Cy", "role": "admin"}
]}

By position: 4 changes (item 1’s id and name, an added role, a removed item 2). Matched by id: 2 changes: $["users"][?@["id"]==2] removed and $["users"][?@["id"]==3]["role"] added.

The path uses the filter form from JSONPath (RFC 9535), so it names the item rather than a position that has moved. Matching is used only for an array in which every item on both sides is an object with that property, holding a unique string or number. Otherwise that array falls back to position (or to an unordered comparison if that option is on), and the report says so.

Ignore timestamps and request IDs

Fields such as updatedAt, requestId or etag change on every response and hide the differences you care about. There are two ways to skip them, and the downloaded report records both.

OptionYou enterWhat is skipped
Ignore keysupdatedAt, requestIdEvery property with that name, at every depth, including inside arrays compared without order
Ignore paths/items/0/updatedAtOnly the value at that one location, written as a JSON Pointer

Separate paths with commas. Inside a pointer, ~1 stands for a / in a key and ~0 for a ~. You do not have to write one by hand: select Ignore on a change and its path is added for you. If a path reaches nothing that was compared, the report says so, which usually means a typo.

What the index in a path means

Take the two users lists above. With items matched by id, /users/2/role skips the new role on Cy, who is third in A and second in B; only the removal of id 2 is left. An added or removed value is listed whole, so a path pointing inside one does not edit it.

How numbers are compared

Numbers are compared by exact decimal value. How a number is written never counts as a difference, and no digit is rounded away. A plain JavaScript comparison cannot do this, because JSON.parse turns both long IDs below into the same 12345678901234567000.

ABResult
1234567890123456789012345678901234567891Changed
0.10000000000000000000010.1Changed
1.101.1Same value, not listed
1001e2Same value, not listed
0-0Same value, not listed
1"1"Changed (number → string)

This matches how RFC 6902 defines the test operation: numbers are equal if they are numerically equal. When numbers differ only in how they are written, the report says how many, and the downloaded report has the count as sameValueNumbers. If a trailing zero matters to you, as it might in a signed payload, compare the text instead: quote the value as a string in both documents.

Where the rule applies

WhereWhat happens
By path, Ignore array order, Match array items byCompared by value, so ids 1.0 and 1 pair up and [1.10, 2] equals [2, 1.1].
Before and After, the JSON report, FormatShown as your document wrote it: 1.10 stays 1.10.
JSON Patch exportThe value is written as in B, with every digit. No operation is produced for numbers of equal value.
Apply a JSON PatchValues keep their digits, and test compares by value.
Line by line, Download .diffBoth documents are normalized, so equal numbers give equal lines: 1.10 and 1e0 appear as 1.1 and 1. Long numbers keep every digit.

The tool that reads your export has to keep those digits too. If it parses numbers as doubles, as JavaScript’s JSON.parse does, it rounds them whatever this page wrote. RFC 8259 warns about this: numbers beyond double precision may not survive other software. For IDs, a string is still the safest format.

Export a JSON Patch

Download JSON Patch saves an RFC 6902 list of add, remove and replace operations that turns document A into document B, using JSON Pointer paths such as /limits/seats. Trailing array items are removed from the end so each index is valid when it is applied.

The patch is available when arrays are compared by position or as whole arrays. It is not offered when items are matched by id, because the pairing does not say where an item should sit, or when the report hit its 2,000-change limit. Ignored keys and paths are not in the patch. The JSON Patch generator page shows a full patch, how to apply it in JavaScript or Python, and what it cannot express.

Before using a report

File contents are read and compared in this tab, without an upload endpoint. Your JSON is not saved; only your comparison options are remembered in this browser. Read the privacy notice.

More on this site

Reference

RFC 8259 — JSON, RFC 6902 — JSON Patch, RFC 9535 — JSONPath. The examples describe this tool’s behavior; check the requirements of your own system before relying on an output.