Test JSON Patch operations online
JSON Patch (RFC 6902) describes changes to a JSON document as an ordered list of operations. Each operation names an op, a path written as a JSON Pointer, and a value or from where needed. It is sent with Content-Type: application/json-patch+json and is used by ASP.NET Core, Kubernetes --type json, Azure DevOps and many REST APIs.
This tester applies your operations one by one. If all succeed you see the final document; if one fails, processing stops and the message tells you which operation broke and why, the same all-or-nothing behavior a compliant server should have.
The six operations
| op | What it does | Fails when |
|---|---|---|
add | Adds a key, or inserts into an array at an index (- means the end) | The parent does not exist, or the index is beyond the array length |
remove | Deletes a key or array element | The path does not exist |
replace | Replaces an existing value | The path does not exist |
move | Removes the value at from and adds it at path | from is missing, or you move a value into its own child |
copy | Copies the value at from to path | from is missing |
test | Checks that the value at path equals value | The values differ |
Example
Document:
{"name": "Widget", "price": 10, "tags": ["a", "b"]}
Patch:
[
{ "op": "test", "path": "/price", "value": 10 },
{ "op": "replace", "path": "/price", "value": 12 },
{ "op": "add", "path": "/tags/1", "value": "x" },
{ "op": "move", "from": "/name", "path": "/title" }
]
Result:
{
"tags": ["a", "x", "b"],
"price": 12,
"title": "Widget"
}
Adding at /tags/1 inserts before the existing element rather than overwriting it. replace and move re-add their keys, so key order can change; JSON objects are unordered, so this does not affect meaning.
Reading error messages
Operation #2 (test): test failed: value at /price is 12means an earlier operation already changed the value. Tests check the document as it is at that step, not the original.Operation #1 (remove): Path /stock does not exist.Unlike merge patch, removing a missing key is an error.array index "5" out of rangeappears when youaddpast the end of an array. Use/-to append.Invalid JSON Pointermeans a path does not start with/. The whole document is the empty path"", not"/".
JSON Pointer escaping
Paths use JSON Pointer (RFC 6901). A / inside a key is written ~1 and a ~ is written ~0, so the key "a/b" is addressed as /a~1b. If you are unsure of a path, click the value in the JSON path finder and copy its JSON Pointer.
JSON Patch vs. merge patch
JSON Patch can set explicit null values, edit single array items and guard changes with test. JSON Merge Patch is simpler to write but replaces arrays wholesale and uses null to delete. To produce a patch automatically from two versions of a document, use the JSON Patch generator.
Privacy
Patches are applied in your browser. Your document and operations are never uploaded.