AZ Tools

JSON Patch Builder (RFC 6902)

Developer

RFC 6902 JSON Patch is a wire format for describing changes to a JSON document — useful for PATCH requests, optimistic updates, undo history, and operational transforms. This tool does both directions: paste a source and target JSON, get the minimal patch that converts one to the other; or paste a source and a patch, see the result after applying. The diff uses recursive structural comparison with `~0`/`~1` JSON Pointer escaping for keys with slashes or tildes. The apply side honors all six ops including `test` (assertion fails throw an error), `copy`, and `move`. Useful for testing patches before hitting your server, or working out the right ops by example.

Patch (RFC 6902)
[
  {
    "op": "replace",
    "path": "/age",
    "value": 31
  },
  {
    "op": "replace",
    "path": "/address/city",
    "value": "Busan"
  },
  {
    "op": "remove",
    "path": "/address/zip"
  },
  {
    "op": "add",
    "path": "/address/country",
    "value": "KR"
  },
  {
    "op": "replace",
    "path": "/tags/1",
    "value": "owner"
  },
  {
    "op": "add",
    "path": "/tags/2",
    "value": "user"
  }
]

Pure RFC 6902 — supports add, remove, replace, move, copy, test ops with `~0`/`~1` pointer escaping.

How to use

  1. Diff mode: paste source and target, see the patch JSON. Edit either side to see how the patch changes.
  2. Apply mode: paste source and a patch array, see the resulting document. Errors (bad pointer, failed `test`) show inline.
  3. JSON Pointer syntax: `/foo/0/bar` walks `foo.0.bar`. Escape `/` as `~1`, `~` as `~0`. Trailing `-` in an array path means 'append'.

Frequently asked questions

Why not just send the new document?
Bandwidth for one. Concurrency for two: if Alice and Bob both edit a doc, you can merge their patches semantically (`replace /name` is compatible with `add /tags/-`), while two full docs would have to pick a winner. Plus, patches are a precise audit trail of what changed and when.
Is this the same as JSON Merge Patch (RFC 7396)?
No. Merge Patch is simpler — you send a partial document where present keys overwrite and `null` deletes. It's easier for humans but loses precision (can't add to an array, can't represent literal `null` values, no atomic test). RFC 6902 (this tool) is the precise wire format. RFC 7396 is the convenience format.

Related tools