JSON Patch vs JSON Merge Patch: which to use

short answer

JSON Merge Patch (RFC 7396) is a partial document: send only the fields you want to change, and null to delete one. It is easy to read and write, but it cannot set a value to null and it replaces arrays whole.

JSON Patch (RFC 6902) is a list of operations with exact paths. It is more verbose, but it can edit single array items, set null, move and copy values, and test a value before changing it.

The same change, both ways

Rename the document, delete the author's email and replace the tags. Both patches below produce the same result.

Document
{
  "title": "Release notes",
  "author": {
    "name": "Ada",
    "email": "ada@example.com"
  },
  "tags": [
    "draft",
    "internal"
  ],
  "pinned": false
}
Result (both patches)
{
  "title": "Release notes 2.0",
  "author": {
    "name": "Ada"
  },
  "tags": [
    "public"
  ],
  "pinned": false
}
JSON Merge Patch
{
  "title": "Release notes 2.0",
  "author": {
    "email": null
  },
  "tags": [
    "public"
  ]
}
JSON Patch
[
  {"op":"replace","path":"/title","value":"Release notes 2.0"},
  {"op":"remove","path":"/author/email"},
  {"op":"replace","path":"/tags","value":["public"]}
]

The Merge Patch mirrors the shape of the document, so it reads like the change you have in mind. The JSON Patch spells out each operation and path, which is longer but unambiguous.

How Merge Patch works

  • If the patch is an object, each of its keys is applied to the target: a value replaces or adds that key, and null removes it.
  • Nested objects merge recursively, so {"author":{"email":null}} touches only author.email.
  • Anything that is not an object, including an array, replaces the target value completely.
  • It is sent as Content-Type: application/merge-patch+json, usually with the HTTP PATCH method.

What Merge Patch cannot do

Set a value to null

Because null means delete, the Merge Patch {"nickname":null} turns {"nickname":"Ada"} into {}. There is no way to keep the key with a null value. JSON Patch can: {"op":"replace","path":"/nickname","value":null} gives {"nickname":null}.

Change one array item

To append "d" to {"tags":["a","b","c"]} with a Merge Patch, you must send the whole new array. Two clients doing that at the same time will lose one of the changes. JSON Patch appends with {"op":"add","path":"/tags/-","value":"d"} and gives {"tags":["a","b","c","d"]} without knowing the current items.

Check before writing

Merge Patch has no equivalent of the JSON Patch test operation. To avoid overwriting someone else's change you need HTTP conditional requests (ETag and If-Match), which work with either format.

Side-by-side comparison

JSON Merge PatchJSON Patch
StandardRFC 7396RFC 6902
Media typeapplication/merge-patch+jsonapplication/json-patch+json
FormatA partial copy of the documentAn array of operations
Delete a fieldSet it to nullremove
Set a field to nullNot possiblereplace or add with null
Edit one array itemNot possible; send the whole arrayBy index, or append with -
Move or copy valuesNomove, copy
Conditional updateOnly through HTTP headerstest, plus HTTP headers
Applying it twiceSame result as onceCan differ (for example, appending twice)

Which one to use

Use Merge Patch for settings, profiles and other documents made of objects with simple values, where nobody needs to store null. It is what most people mean by "send only the changed fields", and many APIs accept it.

Use JSON Patch when documents contain arrays that several clients edit, when null is a meaningful value, or when you want a precise, auditable record of what changed. It is also the better format for storing a change history.

Either way, check the result. Paste the document before and after into the compare tool to confirm the patch changed exactly what you meant and nothing else.

Every result shown in this guide was computed when the page was built, by the same code that runs the JSON compare tool, and is checked by automated tests.