Skip to content
AZ Tools

JSON Merge Patch (RFC 7386)

Apply or generate an RFC 7386 JSON merge patch, with every change listed — including the null that deletes a key rather than setting one.

Result

What the merge did

  • /title — set to "Hello!"
  • /phoneNumber — set to "+01-123-456-7890"
  • /author/familyName — deleted, was "Doe"
  • /tags — replaced wholesale with ["example"]

RFC 7386, media type application/merge-patch+json. Arrays are always replaced whole, never merged.

How to use

  1. Paste the target document and the merge patch to see the result and a list of every key the merge touched.
  2. Switch to the second mode and paste two documents to get the patch that turns the first into the second.
  3. Read the change list rather than only the result: a deletion and a value that was never there look identical in the output.
  4. Load the example from the RFC to see all three rules at once — a replaced string, a deleted nested key and a wholesale array.

About this tool

Show

Apply a merge patch to a document, or work out the patch that turns one document into another, and see key by key what the merge actually did. JSON merge patch is the application/merge-patch+json body that kubectl patch --type=merge sends and that many HTTP APIs accept, and it is a different format from RFC 6902 JSON Patch despite the similar name: a merge patch is just a document shaped like the target, not a list of operations, so it is far easier to write by hand and far easier to get subtly wrong. Three rules account for almost every surprise. A null value deletes its key rather than setting it to null, which means a merge patch cannot express "set this field to null" at all — if your API needs that, merge patch is the wrong format. An array is always replaced whole, never merged, so there is no way to add one element to a list or to change one element of it. And a patch that is not an object replaces the entire target, so sending null as the patch wipes the document and sending a string leaves you with a string. The tool shows each of these as it happens: which keys were set, which were deleted and what they held, and which values were taken wholesale. Generating a patch is not defined by the specification, and the natural minimal diff has the same blind spot in reverse — a target containing a literal null cannot be reproduced, and this tool says so rather than emitting a patch that quietly deletes the field.

Frequently asked questions

How is this different from JSON Patch (RFC 6902)?

RFC 6902 is a list of explicit operations — add, remove, replace, move, copy, test — each with a JSON Pointer path, so it can target one array element and it can set a value to null. A merge patch is a document that mirrors the target, so it is much shorter and readable for ordinary field updates, but it cannot address inside an array and cannot set null. Choose 6902 when you need precision, merge patch when you need brevity.

Why did my patch delete a field I wanted to set to null?

Because that is what the format says: in a merge patch, null means remove this member. There is no escape or alternative spelling. If the value genuinely needs to become null, use RFC 6902 JSON Patch, or have the API accept a sentinel of its own — merge patch has no way to express it.

Can I append one item to an array?

No. Arrays are replaced whole, so the patch has to carry the complete new array. This is deliberate: merging arrays by position would be ambiguous for anything but the simplest edit, and merging by identity would need the format to know what identity means in your data. If element-level edits matter, RFC 6902 addresses array positions directly.

What happens if the patch is not an object?

It replaces the target entirely, whatever the target was. A patch of null produces null, a patch of "bar" produces "bar", and an array patch produces that array. The specification is explicit about it, and this tool warns when the patch is in that shape, because it is almost never what someone sending a PATCH request meant.

Is the generated patch the only correct one?

No. The specification defines applying a patch, not producing one, so any patch that transforms the source into the target is valid. This tool emits the minimal one: only members whose values differ, plus a null for every member the target dropped. A larger patch that restates unchanged members applies just as correctly.

Related tools