JSON Diff Online
Compare two JSON documents structurally and get a JSON Patch (RFC 6902) and Merge Patch (RFC 7386); apply patches to a document.
Result
Press “Run” to see the result.
The JSON diff API compares two JSON values by structure, not by text: key order and formatting do not matter. action=diff (with a and b) returns whether they are equal, a summary of added, removed and replaced values, an RFC 6902 JSON Patch that turns a into b and the equivalent RFC 7386 Merge Patch, the format used by many REST APIs for PATCH requests.
action=patch applies a JSON Patch (add, remove, replace, move, copy, test) to a document and returns the result; a failing test or a missing path returns 422 with the index of the operation, so patches can be validated before they reach your database. action=merge applies a Merge Patch (null removes a key).
Arrays are compared after removing their common beginning and end, so appending or removing items produces short patches. Paths use JSON Pointer with ~0 / ~1 escaping.
Use this in your code
curl -X POST "https://apibox.io.vn/v1/json-diff" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"a":{"name":"A","tags":["x"],"n":{"a":1,"b":2}},"b":{"name":"B","tags":["x","y"],"n":{"a":1}}}'const res = await fetch('https://apibox.io.vn/v1/json-diff', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"a": {
"name": "A",
"tags": [
"x"
],
"n": {
"a": 1,
"b": 2
}
},
"b": {
"name": "B",
"tags": [
"x",
"y"
],
"n": {
"a": 1
}
}
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/json-diff",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"a": {"name": "A", "tags": ["x"], "n": {"a": 1, "b": 2}}, "b": {"name": "B", "tags": ["x", "y"], "n": {"a": 1}}},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/json-diff');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"a":{"name":"A","tags":["x"],"n":{"a":1,"b":2}},"b":{"name":"B","tags":["x","y"],"n":{"a":1}}}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));API documentation → Get a free API key
FAQ
JSON Patch or Merge Patch?
JSON Patch is a list of precise operations (including array positions and tests). Merge Patch is a partial document: simpler, but it cannot set a value to null or change part of an array.
Does key order matter?
No. {"a":1,"b":2} equals {"b":2,"a":1}. Array order does matter.
What happens when a patch fails?
Nothing is applied; you get HTTP 422 with code patch_failed and the index of the failing operation.