Compare two JSON inputs with side-by-side or unified line diffs. Optionally sort keys and arrays recursively; validate JSON in your browser.
Paste JSON payloads into both panes or click 'Load Example' to view differences.
Use this JSON diff tool to compare two JSON documents in your browser. Paste a baseline into Original JSON and the candidate into Modified JSON, or load the example to see the output. The tool validates and formats both inputs, then highlights added, removed, and unchanged lines in Split View or Unified Diff.
Unlike a semantic or schema diff, the result is a formatted line comparison. Matching JSON values are not grouped into property-level changes.
The single most common source of false-positive differences during JSON comparison is arbitrary key order. In many programming environments, dictionaries and associative arrays do not guarantee deterministic iteration orders when serialised into strings. For instance, one service might serialise an address object with the street field first, while another service serialises the postcode first.
According to RFC 8259, which defines the JavaScript Object Notation data format, an object is an unordered collection of zero or more name-and-value pairs.
From a standards perspective, the JSON object {"id": 1, "status": "active"} is semantically identical to {"status": "active", "id": 1}.
When key sorting is omitted, naive comparison algorithms report two separate modifications: a removal of the first key and an addition of the second key.
When Sort JSON recursively is enabled, this tool alphabetically sorts object keys at every depth before formatting and comparison.
This prevents key-order-only differences from appearing in the line diff.
Modern API payloads frequently nest records four, five, or more levels deep. Consider a configuration payload containing database connection pools, authentication providers, and logging rules. If an engineer moves a nested block or re-serialises a config file with a different formatting plugin, nested keys shuffle position. Recursive sorting traverses through nested objects, mapping dictionaries into deterministic order without altering values, ensuring that differences highlighted in the output represent actual configuration shifts rather than cosmetic serialisation noise.
JSON arrays are normally ordered sequences, so different item positions can carry meaning in some data sets. Sort JSON recursively is enabled by default. It sorts object keys and sorts every array, including nested arrays and arrays of objects, before comparison. Array items are ordered by JSON value; object keys inside those items are sorted first.
Sorting arrays means their original positions are ignored. Turn sorting off when the order of steps, events, rows, or other sequence data is meaningful.
Both views use the same formatted line comparison. Choose the one that best fits the way you review changes.
Split View places the baseline on the left and the modified JSON on the right. Line numbers and color highlights make additions and removals easier to scan.
Unified Diff puts both inputs into one sequence. A minus sign (−) marks a removed line, a plus sign (+) marks an added line, and a leading space marks an unchanged line. You can copy or download this view as plain text. The downloaded file is a review summary, not an apply-ready Git patch.
This tool creates a human-readable line comparison. RFC 6902 JSON Patch is a separate format designed to describe changes that software can apply.
| Feature | JSON Diff Tool | RFC 6902 JSON Patch |
|---|---|---|
| Human-readable comparison | Split View and Unified Diff | JSON operation list |
| Sort keys and arrays before comparison | Optional | Not a comparison feature |
| Apply changes programmatically | No | Yes, with a JSON Patch implementation |
Understanding how to compare JSON programmatically allows developers to implement automated integration tests, schema validation pipelines, and change-detection watchers. Below are practical, copy-paste examples in several popular developer environments:
In JavaScript and TypeScript environments, you can normalise keys and verify structural equality using a lightweight recursive function:
function sortObjectKeys<T>(data: T): T {
if (Array.isArray(data)) {
return data.map(sortObjectKeys) as unknown as T;
}
if (data !== null && typeof data === "object") {
const sorted: Record<string, unknown> = {};
for (const key of Object.keys(data).sort()) {
sorted[key] = sortObjectKeys((data as Record<string, unknown>)[key]);
}
return sorted as T;
}
return data;
}
function areJsonEquivalent(payloadA: unknown, payloadB: unknown): boolean {
const normA = JSON.stringify(sortObjectKeys(payloadA));
const normB = JSON.stringify(sortObjectKeys(payloadB));
return normA === normB;
}
// Example usage
const original = { b: 2, a: 1 };
const candidate = { a: 1, b: 2 };
console.log(areJsonEquivalent(original, candidate)); // Returns true
In Python, the deepdiff package is the gold standard for comprehensive structural comparison, offering automated key-order exclusion, type checking, and numerical tolerance:
import json
from deepdiff import DeepDiff
baseline_json = """
{
"service": "billing",
"limits": {"rate": 100, "burst": 200},
"roles": ["read", "write"]
}
"""
modified_json = """
{
"service": "billing",
"limits": {"burst": 200, "rate": 150},
"roles": ["read", "write", "admin"]
}
"""
data_a = json.loads(baseline_json)
data_b = json.loads(modified_json)
# ignore_order=True ignores dictionary key sequence and set-like array orders
diff = DeepDiff(data_a, data_b, ignore_order=True)
print(json.dumps(diff.to_dict(), indent=2, default=str))
If you are working in a terminal or inside a continuous integration shell script, the ubiquitous jq utility can format and sort keys prior to piping into diff:
# Compare two JSON files on the command line while ignoring key order
diff -u <(jq -S '.' payload-v1.json) <(jq -S '.' payload-v2.json)
The -S flag instructs jq to sort object keys alphabetically before pretty-printing, eliminating arbitrary ordering discrepancies directly within your bash workflow.
The JSON parsing, sorting, formatting, and diff calculation run in the browser; the comparison is not sent to a JSON-processing API. The website also loads site-wide analytics and advertising scripts. Avoid pasting credentials or personal data into any online tool unless its privacy practices meet your requirements.
This website and utility are provided for general informational, calculation, and educational purposes only. Always verify critical computation outputs prior to professional deployment or financial use. See our Terms of Service and Privacy Policy for full governance details.