Developer and Text Tools

JSON Patch vs Merge Patch: How to Write and Test Partial Updates

Understand RFC 6902 JSON Patch, RFC 7386 Merge Patch and JSON Pointer paths, avoid the common mistakes, and test a patch step by step before you send it.

Saizul Amin
Saizul Amin3 Nov 2026 · 4 min read
JSON Patch vs Merge Patch: How to Write and Test Partial Updates

Sending a whole document to change one field is wasteful and risky: two clients editing at the same time overwrite each other. That is why many APIs accept partial updates through HTTP PATCH. Two formats dominate, JSON Patch and JSON Merge Patch, and both rely on a third standard, JSON Pointer. This guide explains each one and shows how to test a patch safely.

JSON Pointer: addressing one value

A JSON Pointer is a path made of keys separated by slashes. /owner/team means the member team inside the member owner. Array elements are addressed by index, so /servers/0 is the first server. The empty string points to the whole document.

Two characters need escaping inside a key. A tilde is written ~0 and a slash is written ~1, so the key a/b becomes /a~1b. Forgetting this is one of the most frequent reasons a patch fails with "path not found".

JSON Patch: a list of operations

RFC 6902 defines a patch as an array of operations, each with an op and a path:

  • add inserts a value. In an array it shifts later items; the special index - appends to the end.
  • remove deletes the value at the path.
  • replace changes an existing value; the path must exist.
  • move and copy take a from pointer.
  • test checks that a value equals what you expect.

The whole patch is atomic. If any operation fails, the server must leave the document unchanged. That makes test very useful: put a test of the version or an ETag-like field first, and the patch only applies to the version you looked at.

Merge Patch: a partial document

RFC 7386 takes a simpler approach. You send an object that looks like the parts you want to change. Members are merged recursively, and a member set to null is deleted. It is pleasant to write by hand, but it has two limits. Arrays are always replaced as a whole, so you cannot append one tag. And you cannot set a value to null, because null means delete. If either matters, use JSON Patch.

Typical mistakes

  • A path without the leading slash, such as owner/team.
  • An index one past the end of the array with replace or remove.
  • Using replace on a member that does not exist yet, where add was needed.
  • Expecting a merge patch to add to an array.
  • A test value of "1" against the number 1; JSON types must match exactly.

Testing a patch before it reaches the API

The JSON Patch, Merge Patch and JSON Pointer Workbench runs the same rules in your browser.

  1. Paste the current document as the source.
  2. In Apply JSON Patch paste the operations. Every step gets a tick or a cross with the reason, and the final document appears below.
  3. Tap a step, or use Prev and Next, to see the document right after that operation. This makes move and copy easy to follow.
  4. If a step fails, the panel says that nothing was applied, just as a compliant server would behave.
  5. After a successful run, Invert patch creates the operations that undo it, ready to keep as a rollback.

Apply Merge Patch shows the merged result of an RFC 7386 body. Create patch compares the source with a target and writes the operations for you, then applies them to confirm the result matches the target exactly. If the target contains null values and you choose merge patch output, the tool warns that the result cannot be exact. Pointer tester lists every pointer in the document, already escaped, so you can copy the right one.

When to choose which format

Use Merge Patch for simple form saves where a client sends the changed fields of a settings object. Use JSON Patch when you need to change arrays precisely, guard against concurrent edits with test, rename or move members, or set explicit nulls. Many APIs, including Kubernetes, accept both, with different content types: application/json-patch+json and application/merge-patch+json.

A note on generated patches

Generated patches compare arrays by position. Inserting an item at the start of a long list produces several replace operations instead of one add. The result is still correct, and verified, but if size or readability matters, edit array changes by hand.

Summary

Partial updates save bandwidth and avoid lost edits, but they are unforgiving about paths and types. Write the patch, step through it against a real document, add a test for the version, and keep the inverse patch for rollback.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages