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.
{
"title": "Release notes",
"author": {
"name": "Ada",
"email": "ada@example.com"
},
"tags": [
"draft",
"internal"
],
"pinned": false
} {
"title": "Release notes 2.0",
"author": {
"name": "Ada"
},
"tags": [
"public"
],
"pinned": false
} {
"title": "Release notes 2.0",
"author": {
"email": null
},
"tags": [
"public"
]
} [
{"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
nullremoves it. - Nested objects merge recursively, so
{"author":{"email":null}}touches onlyauthor.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 HTTPPATCHmethod.
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 Patch | JSON Patch | |
|---|---|---|
| Standard | RFC 7396 | RFC 6902 |
| Media type | application/merge-patch+json | application/json-patch+json |
| Format | A partial copy of the document | An array of operations |
| Delete a field | Set it to null | remove |
| Set a field to null | Not possible | replace or add with null |
| Edit one array item | Not possible; send the whole array | By index, or append with - |
| Move or copy values | No | move, copy |
| Conditional update | Only through HTTP headers | test, plus HTTP headers |
| Applying it twice | Same result as once | Can 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.