| Operation | JSON Pointer Path | Original Value | New Value |
|---|
[]
Standard text diffing tools (such as UNIX diff or Git diff) treat files as linear arrays of text lines using the Myers Longest Common Subsequence (LCS) algorithm. When applied to JSON documents, text-based diffing frequently produces noisy, misleading results:
{"a": 1, "b": 2} and {"b": 2, "a": 1} are mathematically equivalent, yet a text diff will falsely report both lines as changed.Semantic JSON diffing operates on the deserialized Abstract Syntax Tree (AST):
"100" vs integer 100), a replace operation is immediately emitted.add).remove).Defined by the IETF in RFC 6902, a JSON Patch document is a JSON array of mutation operations used in HTTP PATCH request bodies. Each operation object defines:
Operation (op) |
JSON Pointer (path) |
Payload | Description |
|---|---|---|---|
add |
/users/0 |
value: {...} |
Inserts an element into an array or creates a new object property. |
remove |
/settings/theme |
None | Deletes a property from an object or removes an index from an array. |
replace |
/profile/email |
value: "new@..." |
Replaces the existing value at the target path. |
move |
/to/path |
from: "/from/path" |
Removes a value from a path and inserts it into a new path. |
copy |
/to/path |
from: "/from/path" |
Duplicates a value to a new location. |
test |
/version |
value: 1 |
Asserts that a path has an exact value before applying mutations. |
Target paths in RFC 6902 utilize RFC 6901 JSON Pointers:
/ and separate object keys or array indices by slashes (e.g. /users/2/addresses/0/zip).~0 represents a literal ~ and ~1 represents a literal /.add, remove, replace). RFC 7386 (JSON Merge Patch) is a simplified mirror document where setting a key to null deletes it, but it cannot delete array elements or distinguish between a property set to null versus deleted.fast-json-patch (Node.js) or jsonpatch (Python).