JSON Merge Patch: Update part of a JSON object concisely
JSON Merge Patch describes changes with a document shaped like the target JSON. In an HTTP PATCH request, use media type application/merge-patch+json. Object members are added or replaced recursively; null removes an existing member. This can be a poor fit when explicit null values must be preserved or only part of an array should change.
JSON Merge Patch describes changes with a document shaped like the target JSON. In an HTTP PATCH request, use media type application/merge-patch+json. Object members are added or replaced recursively; null removes an existing member. This can be a poor fit when explicit null values must be preserved or only part of an array should change.
How partial object updates work
Suppose a resource has displayName, a nested preferences object, and a tags array. A patch such as {"displayName":"Minji","preferences":{"theme":"dark"}} changes the name and nested theme while leaving other object members in place. Objects merge recursively. A new member is added; an existing member's value is replaced. A non-object value replaces the target as a whole, so sending one array element still replaces the entire array.
Null means deletion
When a member in the patch object has value null, the corresponding target member is removed. For example, {"preferences":{"digest":null}} removes preferences.digest. If the API must distinguish setting a field to null from removing it, Merge Patch may be ambiguous. RFC 7396 is mainly suited to object documents that do not need to store explicit null as data.
Choosing between formats
Merge Patch has an object-shaped body and uses null for member deletion; JSON Patch uses an ordered operation array and a remove operation. Merge Patch replaces arrays as a whole; JSON Patch can edit array indexes. JSON Patch also has a test operation for checking a document value. Use Merge Patch when simple object edits and null-as-deletion fit the model. Consider JSON Patch or a documented API-specific format when changing one array element or preserving explicit null. Check supported types in Accept-Patch or API documentation.
Concurrency and verification
Merge Patch does not prevent overwriting newer data. If the API supports ETags, send a strong ETag in If-Match and apply only to the version read. On a failed condition, reread and reconcile. Before release, verify nested merge, whole-array replacement, null deletion, rejection of malformed or unauthorized changes, and conflict behavior without partial updates.
Sources
[RFC 7396: JSON Merge Patch](https://www.rfc-editor.org/rfc/rfc7396.html)
[RFC 5789: PATCH Method for HTTP](https://www.rfc-editor.org/rfc/rfc5789.html)
[RFC 6902: JSON Patch](https://www.rfc-editor.org/rfc/rfc6902.html)
[RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html)