X Xerobit

Compare JSON

Compare two JSON values structurally. Walks both trees and reports every added, removed, and changed field with its full path. Not a string diff — works even when formatting or key order differs.

Paste two JSON values. Diff runs automatically.

How to compare JSON — two steps

  1. Paste the first JSON into the left panel and the second JSON into the right panel. Both must be valid JSON — if either panel has a parse error, it is highlighted in red before the diff runs.
  2. Read the diff report. The tool walks both trees and outputs three categorized lists: Added paths (exist in B, not A), Removed paths (exist in A, not B), and Changed paths (exist in both but with different values). Unchanged paths are not shown — the output only surfaces what actually differs.

Each path in the report uses dot notation for object keys (user.profile.email) and bracket notation for array indices (items[3].price). You can immediately locate the differing node in either input panel by navigating to that path.

Why structural diff, not string diff?

A text diff tool — like git diff or a side-by-side text comparison — compares bytes. For JSON, this produces false positives on every reformatting: a document pretty-printed with 2-space indent looks completely different from the same document with 4-space indent, even though they represent identical data. Key ordering is even worse: {"a":1,"b":2} and {"b":2,"a":1} are the same JSON object, but a text diff marks every line as changed.

A structural diff parses both documents into in-memory trees first, then compares the trees. Key order within objects is ignored — the diff engine sorts keys before comparing. Whitespace and formatting differences disappear entirely. Only semantic differences — a value that changed, a key that was added or removed — appear in the output.

This matters in practice every time you compare an API response captured last week against one captured today, or a config file before and after a deployment. Text diff would flag every reformatting change. Structural diff shows you only what actually changed.

How differences are classified

Type changes are reported as Changed. If a field was "count": "5" (string) in A and "count": 5 (number) in B, that appears as a Changed path — because the values are not strictly equal even though they look similar. This is intentional: strict equality is what JSON serializers and deserializers use.

Structural diff vs text diff — when to use each

ScenarioUse structural diffUse text diff
API response changed between deploysYesNo — key order may differ
Config file, same formatter both timesYesAcceptable
Checking if reformatting changed contentYesNo — always shows changes
Git commit review of JSON fileYesWorks if normalized
Non-JSON text (YAML, TOML, ini)NoYes
Comparing JSON comments (JSON5)No — convert firstYes

Array diff strategy: index-by-index

Arrays are compared position-by-position. Element 0 in A is compared to element 0 in B, element 1 to element 1, and so on. If one array is longer, the extra elements are reported as Added or Removed.

This is the correct strategy for the primary use cases of this tool: comparing API responses where array order is meaningful (a paginated list of results), and comparing config arrays where each index has a defined role.

An alternative is LCS (Longest Common Subsequence) or Myers diff — the algorithm used by git diff. LCS tries to detect items that shifted position and classify them as "moved" rather than "removed from index 2, added at index 5." LCS is computationally heavier (O(n²) worst case) and produces longer, harder-to-read output for config/API comparison. Index-wise diff is O(n) and produces clean output for the common case.

If you need to detect moved items in large JSON arrays — for example, comparing two sorted datasets where elements shuffled — the right tool is jq with custom sorting or a purpose-built LCS differ. For API and config comparison, index-by-index is what you need.

JSON Patch (RFC 6902) vs JSON Diff — different purposes

JSON Patch (RFC 6902) is a machine-applicable operation list:

[
  { "op": "replace", "path": "/user/email", "value": "new@example.com" },
  { "op": "add", "path": "/user/phone", "value": "+1-555-0100" }
]

A JSON Patch document tells a system exactly what to do to transform document A into document B. It is designed to be sent over a network (PATCH request), stored in a database, or applied by a library like fast-json-patch.

This tool produces a human-readable diff — a list of what changed, designed for a developer to read and understand, not for a machine to apply. The two formats serve different workflows. Generating RFC 6902 patch output from the diff is on the roadmap.

Practical use cases

Handling large JSON documents

The diff algorithm is O(n) in the number of leaf nodes across both documents. Memory usage scales with the size of both parsed trees. In practice:

For very large JSON comparison, the command-line tool jq is the right choice. The pattern jq --sort-keys . a.json > a_sorted.json && jq --sort-keys . b.json > b_sorted.json && diff a_sorted.json b_sorted.json normalizes key order and produces a text diff that is meaningful for large files without loading everything into browser memory.

FAQ

Can I diff YAML or JSON5 directly?

Not directly — this tool requires valid JSON on both sides. Convert YAML to JSON first using the YAML ↔ JSON converter. For JSON5, strip comments manually or use a JSON5-to-JSON converter before pasting here.

How large a document can it handle?

Comfortably up to a few megabytes per side. The diff is O(n) in node count and runs entirely in the browser. For documents larger than ~50 MB, use jq --sort-keys to normalize both files, then diff them on the command line.

Is my data private?

Yes. Both JSON inputs are parsed and diffed entirely in your browser using JavaScript. No data is sent to any server. The tool works completely offline once the page is loaded.

Related tools

Related articles

Pillar

Part of Data & Format — JSON, YAML, XML, CSV, SQL, Markdown.


Written by Mian Ali Khalid. Last updated 2026-05-13.