How to Compare Two JSON Files and Find the Differences

Published 24 November 2026 · 5 min read

You have two versions of a JSON file, an API response before and after a deploy, or a config on two servers, and you need to know what changed. A normal text diff is the wrong tool for this, because it compares lines, not meaning.

Why a text diff misleads

  • Formatting. The same data minified and pretty printed differs on every line.
  • Key order. In JSON, an object is an unordered set of keys, so {"a":1,"b":2} and {"b":2,"a":1} are the same value but different text.
  • Number spelling. The values 1.0 and 1 are equal numerically but differ as text.

A structural diff parses both files first, then compares values, so only real changes are reported.

Reading the result

A useful diff lists each change with its path and one of three kinds:

KindMeaningExample path
AddedPresent only in the new file/users/3/phone
RemovedPresent only in the old file/settings/legacy
ChangedSame place, different value/users/0/active

The path tells you where to look, and the numbers in it are array positions starting at 0.

Arrays are the hard part

Objects are compared by key, which is simple. Arrays are compared by position by default, so inserting one item at the top makes every later item look changed. If the order of the array does not matter, such as a list of tags, compare it as an unordered set. If it does matter, an inserted item will shift the rest, and that is correct behavior, not a bug.

Cutting the noise

Fields like timestamps, request IDs and version numbers change on every run. Ignore those fields so the real differences stand out. Compare numbers by value when 1 and 1.0 should match, but keep long IDs exact, since rounding can hide a real change.

Steps

  1. Check both files are valid JSON. If one is not, fix it first; see unexpected token in JSON.
  2. Paste or open the old file on the left and the new file on the right.
  3. Ignore noisy keys and choose whether array order matters.
  4. Read the list of added, removed and changed paths.

The JSON Diff tool does exactly this in your browser, so neither file is uploaded. To tidy a file before comparing, use the JSON formatter.