How to Compare Two JSON Files Online

August 1, 20268 min read

Comparing JSON files is a routine task in software development — catching API response changes between versions, spotting configuration drift between environments, verifying that a data migration produced the expected output, or reviewing exactly what changed in a pull request that modifies a JSON fixture file.

This guide explains the right way to diff JSON, why structural comparison is better than text diff, how JSON Patch works, and how to compare JSON files online for free.

Text Diff vs Structural Diff

A text diff (like git diff or Unix diff) compares files line by line. For JSON, text diffing has two serious problems:

A structural diff compares the JSON values semantically:

JSON Diff Use Cases

Use CaseWhat You're ComparingWhy It Matters
API versioningResponse from v1 vs v2Detect breaking changes before deploying
Config driftDev vs production configEnsure environments are consistent
Data migrationBefore vs after transformationVerify all data was migrated correctly
PR reviewOld JSON fixture vs newUnderstand exactly what test data changed
DebuggingExpected vs actual API responsePinpoint the exact field that is wrong

JSON Patch: RFC 6902

Once you know what changed between two JSON documents, you often want to express that change in a machine-readable way. JSON Patch (RFC 6902) is the standard format for this.

A JSON Patch document is an array of operation objects:

[
  { "op": "add",     "path": "/users/2",        "value": { "id": 3, "name": "Charlie" } },
  { "op": "remove",  "path": "/users/0"                                                  },
  { "op": "replace", "path": "/config/debug",   "value": false                           },
  { "op": "move",    "from": "/temp/name",       "path": "/user/name"                    }
]

The six operation types are: add, remove, replace, move, copy, and test. A JSON Patch document can be applied to a JSON document using any RFC 6902 library to produce the modified version.

Comparing JSON Files Online with IRJSON

IRJSON's diff tool performs a deep structural comparison powered by jsondiffpatch. Paste two JSON documents and see additions (green), deletions (red) and modifications (yellow) highlighted immediately:

Comparing JSON in JavaScript with jsondiffpatch

import * as jsondiffpatch from 'jsondiffpatch'

const left = {
  users: [
    { id: 1, name: 'Alice', role: 'admin' },
    { id: 2, name: 'Bob',   role: 'editor' }
  ],
  version: 1
}

const right = {
  users: [
    { id: 1, name: 'Alice', role: 'superadmin' }, // role changed
    { id: 2, name: 'Bob',   role: 'editor' }
  ],
  version: 2  // version changed
}

const delta = jsondiffpatch.diff(left, right)
console.log(JSON.stringify(delta, null, 2))
// { users: { 0: { role: ['admin', 'superadmin'] } }, version: [1, 2] }

// Apply the patch
const patched = jsondiffpatch.patch(structuredClone(left), delta)
console.log(patched.version) // 2

Comparing JSON in Python with deepdiff

from deepdiff import DeepDiff
import json

left = {
    "users": [
        {"id": 1, "name": "Alice", "role": "admin"},
        {"id": 2, "name": "Bob",   "role": "editor"}
    ],
    "version": 1
}

right = {
    "users": [
        {"id": 1, "name": "Alice", "role": "superadmin"},
        {"id": 2, "name": "Bob",   "role": "editor"}
    ],
    "version": 2
}

diff = DeepDiff(left, right, ignore_order=True)
print(diff)
# {'values_changed': {"root['users'][0]['role']": {'new_value': 'superadmin', 'old_value': 'admin'},
#                     "root['version']": {'new_value': 2, 'old_value': 1}}}

Frequently Asked Questions

Does the JSON diff tool ignore key order?

Yes. IRJSON performs a structural diff. Object key order is entirely irrelevant — only value differences are reported. Two objects with the same keys and values in different order are considered equal.

What is JSON Patch?

JSON Patch (RFC 6902) is a standard format for describing changes to a JSON document as an array of operations: add, remove, replace, move, copy, and test. IRJSON can export diffs as JSON Patch documents that you can apply programmatically.

Can I export the diff result?

Yes. After diffing, click the Export button to download the diff as a JSON Patch (RFC 6902) document.

Compare JSON files for free

IRJSON's structural diff tool highlights every change instantly. No sign-up, no file uploads, 100% private.

Open Diff Tool →