JSON Merge Patch: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | =External= | ||
* https://datatracker.ietf.org/doc/html/rfc7386 | * https://datatracker.ietf.org/doc/html/rfc7386 | ||
* https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/ | |||
* https://erosb.github.io/post/json-patch-vs-merge-patch/ | |||
=Internal= | =Internal= | ||
* [[Kubectl_patch#Overview|kubectl patch]] | * [[Kubectl_patch#Overview|kubectl patch]] | ||
Line 6: | Line 9: | ||
=Overview= | =Overview= | ||
JSON merge patch is defined by [https://datatracker.ietf.org/doc/html/rfc7386 RFC7386]. | JSON merge patch is defined by [https://datatracker.ietf.org/doc/html/rfc7386 RFC7386]. | ||
JSON merge patch defines a JSON document format appropriate for modifying a target JSON document. The format is suitable to use with the [[HTTP_Request#PATCH|HTTP PATCH]] method and an "application/merge-patch+json" media type. | |||
<syntaxhighlight lang='text'> | |||
PATCH /target HTTP/1.1 | |||
Host: example.org | |||
Content-Type: application/merge-patch+json | |||
{ | |||
"a":"z", | |||
"c": { | |||
"f": null | |||
} | |||
} | |||
</syntaxhighlight> | |||
=Behavior on Arrays= | |||
Arrays cannot be manipulated by merge patches. If you want to add an element to an array, or mutate any of its elements then you have to include the entire array in the merge patch document, even if the actually changed parts is minimal. The new list completely replaces the existing list. | |||
=Also See= | |||
{{Internal|JSON Patch|JSON Patch}}{{Internal|Kubernetes Strategic Merge Patch|Kubernetes Strategic Merge Patch}} |
Latest revision as of 19:20, 29 July 2021
External
- https://datatracker.ietf.org/doc/html/rfc7386
- https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/
- https://erosb.github.io/post/json-patch-vs-merge-patch/
Internal
Overview
JSON merge patch is defined by RFC7386.
JSON merge patch defines a JSON document format appropriate for modifying a target JSON document. The format is suitable to use with the HTTP PATCH method and an "application/merge-patch+json" media type.
PATCH /target HTTP/1.1
Host: example.org
Content-Type: application/merge-patch+json
{
"a":"z",
"c": {
"f": null
}
}
Behavior on Arrays
Arrays cannot be manipulated by merge patches. If you want to add an element to an array, or mutate any of its elements then you have to include the entire array in the merge patch document, even if the actually changed parts is minimal. The new list completely replaces the existing list.