JSON Patch Generator
Generate an RFC 6902 JSON Patch document from a source and a target JSON value.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
2 operation(s) turn the source into the target.
How it works
- Walked both values in parallel, matching object keys and array indices.
- Emitted `remove` for a key or element only in the source, `add` for one only in the target, and recursed otherwise.
- Emitted `replace` at a leaf whose value changed, using an RFC 6901 JSON Pointer path.
- Routes are pointer-escaped per RFC 6901: `~` becomes `~0` and `/` becomes `~1`.
- Arrays are diffed positionally (index by index); a reorder is therefore reported as a set of `replace` operations rather than a `move`.
Methodology
- Parse both values.
- Recurse over objects by key and arrays by index.
- Emit add/remove at structural differences and replace at changed leaves.
- Serialise the operations as an RFC 6902 patch array.
Usage
- Paste the source JSON value.
- Paste the target JSON value.
- Copy the generated RFC 6902 patch array.
Examples
These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.
Replace and add
{
"source": "{\"a\":1}",
"target": "{\"a\":2,\"b\":3}"
}Remove a nested key
{
"source": "{\"user\":{\"name\":\"Ada\",\"age\":36}}",
"target": "{\"user\":{\"name\":\"Ada\"}}"
}Array element added
{
"source": "[1,2]",
"target": "[1,2,3]"
}Limitations
Patch versus compare
A JSON Patch is a list of operations that transforms one document into another. It is compact and replayable, which is why it is used for partial updates over HTTP (`application/json-patch+json`).
This generator emits the minimal positional patch. It is ideal for 'make this document look like that one'; for a human-readable side-by-side view, use the JSON Compare tool instead.
Frequently asked questions
- What is a JSON Pointer?
- The path syntax from RFC 6901, e.g. `/a/0/b`; it addresses members and array indices, with `~0`/`~1` escaping for literal `~` and `/`.
- Why is my array reorder so large?
- Because the diff is positional. A `move` would be shorter, but detecting moves reliably is out of scope for this generator.
Sources
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.