Apply a JSON Patch (a list of operations, RFC 6902) or a JSON Merge Patch (RFC 7386) to a document. It runs in your browser.
What it does
Put the document in the first box and the patch in the second, and say which kind of patch it is. The result is the document with the patch applied, and it updates as you type.
Operations (RFC 6902)
A list like [{"op": "replace", "path": "/a", "value": 1}], using add, remove, replace, move, copy and test, each naming its place with a JSON Pointer. They run in order and all or nothing: if one fails (a path that is not there, a test that does not hold) nothing changes and the error names it, as in operation 3 (replace /a/b).
Merge patch (RFC 7386)
A document laid over the other: its members replace or add, a null deletes one, and anything that is not an object replaces what it is laid over. It cannot set a member to null; use operations for that.
Order, and exact numbers
Objects keep the order of their members: a replaced one stays where it was, a new one goes last. Numbers keep every digit. To make a patch from two documents, use Diff.
In your tab
The patch is applied by the same Rust engine as the desktop app, compiled to WebAssembly: nothing is uploaded. This page takes up to 10 MB a box.
Lessons
Samples to study and to try: ▶ Try it puts them in the page.
Operations (RFC 6902)
A JSON Patch is a list of operations, run in order: add, remove, replace, move, copy and test. Each names a place by its JSON Pointer.
Release a new version
Kind: Operations (RFC 6902)
Samples: Document, Patch
Document
{
"name": "orders-api",
"version": "1.4.0",
"debug": true,
"tags": ["api", "beta"],
"owner": { "team": "platform" }
}Patch
[
{ "op": "test", "path": "/version", "value": "1.4.0" },
{ "op": "replace", "path": "/version", "value": "1.5.0" },
{ "op": "remove", "path": "/debug" },
{ "op": "add", "path": "/tags/-", "value": "stable" },
{ "op": "remove", "path": "/tags/1" },
{ "op": "copy", "from": "/owner/team", "path": "/team" },
{ "op": "move", "from": "/owner", "path": "/maintainer" }
]What it gives: 7 operations
{
"name": "orders-api",
"version": "1.5.0",
"tags": [
"api",
"stable"
],
"team": "platform",
"maintainer": {
"team": "platform"
}
}test checks the version is 1.4.0 before anything is changed./tags/- is the end of the array: stable is added last, then /tags/1 (beta) is removed.copy and move take from a place: owner is renamed maintainer, and its team is copied to the top.
All or nothing
When an operation fails — a place that is not there, a test that does not hold — the patch stops, and the document is left as it was: the operations before it are undone.
A test that does not hold
Kind: Operations (RFC 6902)
Samples: Document, Patch
Document
{
"name": "orders-api",
"version": "1.4.0",
"debug": true,
"tags": ["api", "beta"],
"owner": { "team": "platform" }
}Patch
[
{ "op": "replace", "path": "/version", "value": "2.0.0" },
{ "op": "test", "path": "/tags/0", "value": "web" }
]The error
operation 2 (test /tags/0): the value there is "api", not "web"
- The error names the operation, by its number and its place.
- The
replace had worked, and is not kept.
Merge patch (RFC 7386)
A merge patch is a document laid over the other: its members replace or add, objects are merged member by member, and null deletes.
Settings changed with a merge patch
Kind: Merge patch (RFC 7386)
Samples: Document, Patch
Document
{
"name": "orders-api",
"version": "1.4.0",
"debug": true,
"tags": ["api", "beta"],
"owner": { "team": "platform" }
}Patch
{
"version": "1.5.0",
"debug": null,
"tags": ["api"],
"owner": { "email": "[email protected]" }
}What it gives: merge patch
{
"name": "orders-api",
"version": "1.5.0",
"tags": [
"api"
],
"owner": {
"team": "platform",
"email": "[email protected]"
}
}debug: null deletes debug.owner is merged: it keeps team and gains email.- An array is replaced whole:
tags is just ["api"].
Good to know
- A merge patch cannot set a value to
null, nor change one element of an array: that takes the operations of RFC 6902.
Your own queries, schemas, patches, documents and web addresses, kept in folders, with a sample if you like. It is the desktop app's workspace: a folder of the app opens here. This needs JavaScript.