jsondiffcompareapidebugging

JSON Diff — How to Compare Two JSON Objects and Find Differences

·6 min read

What Is JSON Diff?

JSON diff compares two JSON objects and shows exactly what changed between them — which keys were added, which were removed, and which values changed. Unlike a text diff that compares raw text line by line, a JSON diff understands the structure and compares it semantically.

Two JSON objects can have keys in different orders and still show as identical, because key order does not affect the meaning of a JSON object.

How JSONKit Diff Works

Open the JSON Diff page at /json-diff. Paste your original JSON in the left panel and your modified JSON in the right panel. JSONKit runs a deep comparison automatically as you type. Results appear in the bottom panel with colour coding:

Green means added — the key exists in the modified JSON but not the original. Red means removed — the key exists in the original but not the modified. Orange means changed — the key exists in both but the value is different, shown as old value with strikethrough then arrow then new value in green.

Only differences are shown by default. If the objects are identical, a confirmation message appears.

Practical Use Cases

API response testing — paste before and after API responses to verify only the expected fields changed. Configuration comparison — diff two versions of a JSON config file to see what settings changed between deployments. Database record debugging — export before and after states and diff them to find exactly which fields were affected. Code review — paste old and new JSON fixture files to see a clean summary of changes.

Deep Comparison

The diff engine is recursive and compares every nesting level. If one field inside a deeply nested object changed, that specific key path is shown in the results.

Format Both and Swap

Click Format Both to beautify both panels before comparing — useful when one paste comes from a minified source. Click Swap to reverse which JSON is treated as original and which is modified.

JSON Diff in Code

JavaScript:

javascript
function diffObjects(left, right, prefix = "") {
  const changes = [];
  const allKeys = new Set([...Object.keys(left), ...Object.keys(right)]);
  for (const key of allKeys) {
    const fullKey = prefix ? prefix + "." + key : key;
    if (!(key in left))  { changes.push({ type: "added",   key: fullKey, value: right[key] }); continue; }
    if (!(key in right)) { changes.push({ type: "removed", key: fullKey, value: left[key]  }); continue; }
    if (JSON.stringify(left[key]) !== JSON.stringify(right[key])) {
      changes.push({ type: "changed", key: fullKey, left: left[key], right: right[key] });
    }
  }
  return changes;
}

Python:

python
def diff_json(left, right, prefix=""):
    changes = []
    all_keys = set(list(left.keys()) + list(right.keys()))
    for key in all_keys:
        full_key = f"{prefix}.{key}" if prefix else key
        if key not in left:
            changes.append({"type": "added", "key": full_key, "value": right[key]})
        elif key not in right:
            changes.append({"type": "removed", "key": full_key, "value": left[key]})
        elif left[key] != right[key]:
            changes.append({"type": "changed", "key": full_key, "left": left[key], "right": right[key]})
    return changes

Try JSON Diff

Compare two JSON objects and see exactly what changed.