How to use the json patch applier
- Paste the JSON document.
- Paste the JSON Patch, an array of operations.
- Choose the indent of the output.
- Read the patched JSON, or the message that names the first operation that failed.
Formula
add puts a value at a path. On an array it inserts, and the index - means the end
remove deletes the value at a path. replace needs the path to exist already
move takes a value from "from" and adds it at the path. copy does the same without removing it
test compares the value at a path with the value given, and the patch fails if they differ
Paths are JSON Pointers (RFC 6901): ~1 stands for / and ~0 for ~. Operations run in order on a copy of the document.
Six operations on a small document
The document has a name, a list of tags and an owner. The patch tests that the owner id is 7, replaces the owner's email, adds "d" to the end of the tags, removes the first tag, moves the name to a new member called title and copies the title into the owner as label. All 6 operations are applied.
The result has the tags b, c and d, an owner with the new email and the label widget, and the title widget, and no name member. If the test had expected 8 instead of 7, the patch would stop at operation 1 and the result would stay empty with a message saying that the test failed.
What a JSON Patch is for
A JSON Patch describes a change to a document as a list of small steps instead of sending the whole new document. APIs use it for partial updates, editors use it for undo histories, and tools use it to record the difference between two versions. The format is defined in RFC 6902 and is precise about what each step must do, which makes it easy to check.
Applying a patch by hand is error-prone, especially with array indexes that shift after each insert or remove. This page applies the steps in order and tells you where one fails.
Common failures
The usual causes are a path that does not exist, an array index past the end, a replace of a member that is missing, and a test that no longer matches. The tool stops at the first failure and shows nothing, so you never mistake a half applied patch for a result. To create a patch from two documents use the JSON Diff to Patch tool, and to tidy the document use the JSON Formatter and Validator. The JSON Canonicalizer fixes the key order before you hash the result, and the JSON Flatten and Unflatten Tool turns it into dotted paths.
Assumptions and limits
- Both inputs are valid JSON. The tool reports the line of a syntax error when it can.
- Operations follow RFC 6902 and paths follow RFC 6901.
- The document and patch shown are examples. Use your own.
- Everything runs in your browser and nothing is uploaded.
Frequently asked questions
What does the dash at the end of an array path do?
With add, a path ending in - appends the value to the end of the array.
Why did my replace fail?
Replace requires the member or index to exist. Use add to create it, which also overwrites an existing member.
Can a move target a child of its own source?
No. Moving a value into one of its own children is refused, because the value would be inside itself.
Is the original document changed?
No. The tool works on a copy and shows the copy in the result box.