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

Or drop a .json file here.
Operations
2
replace /a
2
add /b
3
[
  {
    "op": "replace",
    "path": "/a",
    "value": 2
  },
  {
    "op": "add",
    "path": "/b",
    "value": 3
  }
]

Supported formats

Input
text
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

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

  1. Parse both values.
  2. Recurse over objects by key and arrays by index.
  3. Emit add/remove at structural differences and replace at changed leaves.
  4. Serialise the operations as an RFC 6902 patch array.

Usage

  1. Paste the source JSON value.
  2. Paste the target JSON value.
  3. 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

jsonSelect to copy
{
  "source": "{\"a\":1}",
  "target": "{\"a\":2,\"b\":3}"
}

Remove a nested key

jsonSelect to copy
{
  "source": "{\"user\":{\"name\":\"Ada\",\"age\":36}}",
  "target": "{\"user\":{\"name\":\"Ada\"}}"
}

Array element added

jsonSelect to copy
{
  "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

  1. RFC 6902: JavaScript Object Notation (JSON) Patch — IETF
  2. RFC 6901: JavaScript Object Notation (JSON) Pointer — IETF