rfc-7386

JSON Merge Patch

P. Hoffman, J. Snell
date2014-10 streamIETF areaart wgappsawg statusPROPOSED STANDARD pages9 canonicalhttps://www.rfc-editor.org/rfc/rfc7386 doi10.17487/RFC7386 errataview
This specification defines the JSON merge patch format and processing rules. The merge patch format is primarily intended for use with the HTTP PATCH method as a means of describing a set of modifications to a target resource's content.

obsoleted by

Extracted elements (14)

design-rationale §1

JSON merge patch uses a syntax that closely mimics the document being modified. Recipients determine changes by comparing the patch against the current target: missing members are added, existing members are replaced, and null signals deletion. This makes patches human-readable without a separate diff language.

json, http

design-rationale §2

MergePatch operates at the level of data items, not textual representation. The operation is not required to preserve whitespace, member ordering, or number precision beyond the target implementation's capabilities. This simplifies implementation by decoupling patch semantics from serialization details.

json

design-rationale §1

Null values in a merge patch are overloaded to mean 'remove this member' rather than 'set this member to null'. As a consequence, the format is unsuitable for JSON documents that legitimately use explicit null values, because there is no way to distinguish a deletion instruction from a real null.

json

design-rationale §1

The format is intentionally limited to object-structured JSON documents. It cannot selectively patch elements within arrays; an array can only be replaced wholesale. This constraint is acknowledged in the spec as a known limitation of the design.

json

interoperability-note §2

If the target implementation allows multiple name/value pairs with the same key (duplicate keys, which RFC 7159 permits but discourages), the result of MergePatch on such objects is explicitly undefined by this specification.

json

interoperability-note §2

It is not possible to use merge patch to modify only part of a non-object value, such as replacing individual elements within an array. Any patch targeting an array position must replace the entire array.

json

normative-requirement §2 MUST

For each Name/Value pair in the patch where Value is null and the Name exists in the Target, the Name/Value pair MUST be removed from Target. If the Name does not exist in Target, the null entry is silently ignored.

json

normative-requirement §2 MUST

If the Patch is an Object but the Target is not an Object, the Target MUST be set to an empty Object before iterating the patch members. The prior non-object content of Target is discarded.

json

normative-requirement §2 MUST

If the Patch is anything other than an Object, the result MUST be to replace the entire Target with the entire Patch. There is no partial application when the patch is a scalar, array, or null.

json

normative-requirement §4 REQUIRED

Resources using the 'application/merge-patch+json' media type are required to conform to the 'application/json' media type and are subject to the encoding considerations in RFC 7159 Section 8.

json, http, registry

protocol-element §2

The MergePatch(Target, Patch) algorithm is the normative processing core: if Patch is an Object, iterate its Name/Value pairs — null values remove the named member from Target, non-null values recursively MergePatch into Target[Name]; if Patch is not an Object, return Patch (wholesale replacement).

json

registry §4

IANA registers the MIME media type 'application/merge-patch+json' (type: application, subtype: merge-patch+json). No required or optional parameters; encoding follows application/json (RFC 7159); change controller is IESG.

registry, json, http

security-consideration §5

All security considerations from RFC 5789 (HTTP PATCH method) apply to every use of HTTP PATCH with the 'application/merge-patch+json' media type, including risks around partial updates and concurrent modification.

security, http

security-consideration §5

The 'application/merge-patch+json' media type lets a user agent instruct a server to determine and apply a specific set of changes. It is the server's responsibility to verify both the appropriateness of the requested changes and the user agent's authorization to make them. The specification does not define how to perform these checks.

security, http