JSON Patch and Merge Patch Explained
2025-12-15
JSON Patch (RFC 6902)
Defines a sequence of operations to precisely control modifications.
[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo" }
]
Features: Atomicity, supports move/copy, explicit semantics.
JSON Merge Patch (RFC 7396)
Resembles simple object merging, using null to indicate deletion.
{
"title": "Hello!",
"author": {
"familyName": null
},
"phoneNumber": "+01-123-456-7890"
}
Features: Simple syntax, no partial array updates (replacement only), cannot set value to null (if null means delete).
Selection Advice
- Simple Updates: Merge Patch suffices for most CRUD scenarios.
- Complex Operations: Use JSON Patch for array manipulation or precise control.
Summary
Choosing the right Patch standard simplifies API design while meeting different data update granularity needs.