JSON Patch

Apply or make a JSON Patch (RFC 6902) or merge patch (RFC 7396), and read JSON Pointers — every failed operation named.

JSON Patch

On this device

JSON document

0 characters

JSON Patch (RFC 6902)

0 characters

Patched document

Paste a document and a patch. Every operation runs in order; if one fails, nothing is changed and the failing one is named.

How is this calculated?
JSON Patch — RFC 6902: operations applied in order to a copy; if any fails, none is applied. JSON Merge Patch — RFC 7396 §2: objects merge member by member, null removes, anything else replaces. JSON Pointer — RFC 6901: /-separated tokens; ~1 is “/”, ~0 is “~”.

Runs in your browser — nothing you enter leaves this device.

About this tool

What it does

A JSON Patch describes a change to a JSON document as a list of operations — add, remove, replace, move, copy and test — each aimed at one place by a JSON Pointer such as /address/city. It is what HTTP PATCH requests with the content type application/json-patch+json carry, and what Kubernetes, many REST APIs and document databases accept. A merge patch (RFC 7396) is the simpler alternative: a partial document whose members replace the target’s, with null meaning “delete”. This tool applies either kind to a document, makes a patch from two versions of one, and shows what any JSON Pointer refers to. It follows RFC 6902, RFC 7396 and RFC 6901 to the letter and is tested on every example those standards publish.

How to use it
  1. Choose Apply a patch, Make a patch or Read a pointer, and for patches choose JSON Patch or Merge patch.
  2. To apply: paste the document on the left and the patch on the right. The patched document appears below.
  3. To make: paste the original on the left and the changed version on the right. The patch that turns one into the other appears below.
  4. To read a pointer: paste a document and type a pointer like /items/0/name.
  5. Copy or download the result. A generated patch downloads with its own media type in mind, as patch.json or merge-patch.json.
Limits and your data
  • A patch is all or nothing (RFC 6902 §5): when an operation fails — a missing member, an index past the end, a failed test — the error names that operation and the document is left exactly as it was.
  • Numbers are kept exactly as written, so 64-bit IDs survive. test compares numbers by value (1.0 equals 1) and objects without regard to member order.
  • A merge patch cannot set a member to null, because null means “remove” in RFC 7396; the tool says where that would be needed and suggests a JSON Patch instead. Arrays in a merge patch replace the whole array.
  • Generated JSON Patches are always correct — applying one to the original gives exactly the changed document — but not always the shortest: arrays are compared position by position, so an item inserted at the front shows as several replaces.
  • Documents up to 5 MB. For larger files use JSON Studio.
  • Everything runs in your browser. The documents and patches you paste are never uploaded, stored or logged, and closing the page clears them.

Questions

What is the difference between JSON Patch and JSON Merge Patch?

JSON Patch (RFC 6902) is a list of explicit operations and can do anything: insert into the middle of an array, move a value, set a member to null, or check a value first with test. Merge patch (RFC 7396) is a partial document that is easier to write by hand, but it cannot touch individual array items or store null. APIs say which one they accept through the content type: application/json-patch+json or application/merge-patch+json.

Why did my patch fail when every operation looks right?

Operations run one after another, each on the result of the last. A remove at /items/0 shifts every later index down by one, so a following operation that still uses the old index points somewhere else or past the end. The error names the operation number and the exact pointer that failed.

How do I point at a key that contains a slash or a tilde?

Escape it: ~1 stands for “/” and ~0 for “~”. The key a/b is /a~1b, and m~n is /m~0n. The empty pointer means the whole document, and / alone means the member whose name is the empty string.

What does "-" mean in a path?

In an add operation, /items/- means “after the last item”, so the value is appended. It is only valid for add; anywhere else it is an error, because there is no item there yet.

Is it safe to paste a patch containing "__proto__"?

Yes. Keys are handled as plain data, so a member named __proto__ or constructor is added, replaced or removed like any other and never changes how JavaScript objects behave in the page.