JSON Diff โ€” Compare JSON Objects

Compare two JSON values in your browser. Lists added, removed, and changed paths with strict equality. Not a line-oriented text diff.

How it works
  • + added path ยท โˆ’ removed path ยท ~ changed value. Object paths use dots (user.name); arrays use indexes (items[0]). Comparison is strict (1 โ‰  "1").

+ added path ยท โˆ’ removed path ยท ~ changed value. Object paths use dots (user.name); arrays use indexes (items[0]). Comparison is strict (1 โ‰  "1").

About JSON diff

What is a JSON diff?

A JSON diff compares two JSON values and lists structural changes by path. This page reports added paths (+), removed paths (โˆ’), and changed values (~).

Work happens in your browser. Object paths use dots (user.name); arrays use indexes (items[0]). Comparison is strict: 1 is not "1". This is not a line-oriented text diff and not a language-specific CLI.

Compare JSON in code

JavaScript
const a = JSON.parse(left);
const b = JSON.parse(right);
function diff(x, y, path = "") {
  if (Object.is(x, y)) return [];
  if (typeof x !== "object" || !x || typeof y !== "object" || !y) return [{ path, from: x, to: y }];
  const keys = Array.from(new Set([...Object.keys(x), ...Object.keys(y)]));
  return keys.flatMap(k => diff(x[k], y[k], path ? `${path}.${k}` : k));
}
const changes = diff(a, b);
Python
import json
a = json.loads(left)
b = json.loads(right)
def diff(x, y, path=""):
    if x == y: return []
    if not isinstance(x, (dict, list)) or not isinstance(y, (dict, list)):
        return [{"path": path, "from": x, "to": y}]
    keys = set(x.keys()) | set(y.keys()) if isinstance(x, dict) else range(max(len(x), len(y)))
    res = []
    for k in keys:
        p = f"{path}.{k}" if path else str(k)
        if k not in x: res.append({"path": p, "added": y[k]})
        elif k not in y: res.append({"path": p, "removed": x[k]})
        else: res.extend(diff(x[k], y[k], p))
    return res
changes = diff(a, b)
Notation
+ user.email = "a@b.c"
- items[1] = 2
~ b 2 -> 3

JSON diff FAQ

What is a JSON diff?
A JSON diff compares two JSON values and lists structural changes by path. This page uses + for added paths, โˆ’ for removed paths, and ~ for changed values.
How are JSON paths written?
Object keys use dots, such as user.name. Array indexes use brackets, such as items[0]. The root path is shown as (root) when the top-level value itself changes.
Is JSON comparison type-strict?
Yes. Values must match in type and content. The number 1 differs from the string "1", and object key order does not matter.
How do I compare JSON in code?
Parse both sides with JSON.parse in JavaScript or json.loads in Python, then walk objects and arrays to report path adds, removes, and changes. This page is a browser tool, not a CLI package.