Blog post
JSON Merge Patch and JSON Patch: Update APIs Without Full Replace
Learn JSON Merge Patch (RFC 7396) and JSON Patch (RFC 6902) for partial updates in REST APIs — with JavaScript and Python examples.
Shashank Jain
Author


Article
The Partial Update Problem
REST APIs often need to update only some fields of a resource. Sending the full object on every update is wasteful and risks overwriting fields the client did not intend to change. Two standards solve this: JSON Merge Patch and JSON Patch.
JSON Merge Patch (RFC 7396)
Send only the fields you want to change. Null means delete the field.
// Original resource
{
"title": "Hello World",
"content": "My first post",
"tags": ["intro", "beginner"],
"published": false
}
// Merge Patch request body
{
"published": true,
"tags": null
}
// Result after merge
{
"title": "Hello World",
"content": "My first post",
"published": true
// tags deleted because value was null
}Applying Merge Patch in JavaScript
function applyMergePatch(target, patch) {
if (typeof patch !== 'object' || patch === null) return patch;
const result = { ...target };
for (const [key, value] of Object.entries(patch)) {
if (value === null) {
delete result[key];
} else if (typeof value === 'object' && !Array.isArray(value)) {
result[key] = applyMergePatch(result[key] || {}, value);
} else {
result[key] = value;
}
}
return result;
}JSON Patch (RFC 6902)
JSON Patch is more powerful — an array of operations:
// JSON Patch operations
[
{ "op": "replace", "path": "/published", "value": true },
{ "op": "add", "path": "/tags/-", "value": "new-tag" },
{ "op": "remove", "path": "/draft" },
{ "op": "move", "path": "/archive/title", "from": "/title" },
{ "op": "copy", "path": "/backup", "from": "/content" },
{ "op": "test", "path": "/version", "value": 3 }
]Applying JSON Patch in JavaScript
// npm install fast-json-patch
const jsonpatch = require('fast-json-patch');
const document = { name: 'Alice', age: 30 };
const patch = [
{ op: 'replace', path: '/age', value: 31 },
{ op: 'add', path: '/email', value: 'alice@example.com' }
];
const result = jsonpatch.applyPatch(document, patch).newDocument;
console.log(result);
// { name: 'Alice', age: 31, email: 'alice@example.com' }Which to Use
| Feature | Merge Patch | JSON Patch |
|---|---|---|
| Simplicity | Very simple | More complex |
| Array operations | Full replace only | Add/remove/move items |
| Atomic operations | No | Yes (test operation) |
| Null deletion | Yes (null = delete) | Explicit remove op |
| Content-Type | application/merge-patch+json | application/json-patch+json |
FAQ
When should I use PATCH vs PUT?
Use PUT to replace the entire resource. Use PATCH for partial updates. PATCH with JSON Merge Patch or JSON Patch is safer for concurrent edits — you only touch the fields you intend to change.
How do I delete a field with JSON Merge Patch?
Set the field to null in the patch body. The server should interpret null as a delete instruction. Note: this means you cannot use Merge Patch to set a field to null — use JSON Patch's remove operation for that.
Is JSON Patch atomic?
Servers should apply all operations or none (rollback on failure). The test operation lets you add preconditions. Check your server library's documentation for atomicity guarantees.
What is the Content-Type for JSON Patch?
Use application/json-patch+json for JSON Patch and application/merge-patch+json for JSON Merge Patch. Some APIs accept application/json for both.
Can I generate a JSON Patch from two objects?
Yes. Libraries like fast-json-patch have a generate function that diffs two objects and produces the patch operations.
Keep reading
Recent blogs

Jun 14, 2026
JSON in C#: System.Text.Json and Newtonsoft Complete Guide
Serialize and deserialize JSON in C# using System.Text.Json and Newtonsoft.Json with practical examples.

Jun 14, 2026
JSON to Markdown Table: Convert JSON Arrays Instantly
Convert JSON arrays to Markdown tables in JavaScript, Python, and with the free online tool.

Jun 14, 2026
JSON in TypeScript: Type-Safe Parsing and Validation
Stop using any for JSON in TypeScript — use Zod, type guards, and generics for fully type-safe parsing.