JSON Patch: Difference between revisions
Jump to navigation
Jump to search
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | =External= | ||
* https://tools.ietf.org/html/rfc6902 | * https://tools.ietf.org/html/rfc6902 | ||
* https://erosb.github.io/post/json-patch-vs-merge-patch/ | |||
* https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/ | * https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/ | ||
=Internal= | =Internal= | ||
* [[JSON]] | |||
* [[JSON Merge Patch]] | * [[JSON Merge Patch]] | ||
* [[Kubectl_kustomize#Overview|kubectl kustomize]] | * [[Kubectl_kustomize#Overview|kubectl kustomize]] | ||
* [[Kubernetes Strategic Merge Patch|Kubernetes Strategic Merge Patch]] | * [[Kubernetes Strategic Merge Patch|Kubernetes Strategic Merge Patch]] | ||
* [[kubectl patch]] | * [[kubectl patch]] | ||
=Overview= | =Overview= | ||
JSON patch is defined in [https://datatracker.ietf.org/doc/html/rfc6902 RFC6902]. | JSON patch is defined in [https://datatracker.ietf.org/doc/html/rfc6902 RFC6902]. | ||
JSON patch defines a JSON document structure for expressing a sequence of operations to apply to a JSON document, in order to change it. The format is suitable to use with the [[HTTP_Request#PATCH|HTTP PATCH]] method and an "application/json-patch+json" media type. | |||
<syntaxhighlight lang='text'> | |||
PATCH /my/data HTTP/1.1 | |||
Host: example.org | |||
Content-Length: 326 | |||
Content-Type: application/json-patch+json | |||
If-Match: "abc123" | |||
[ | |||
{ "op": "test", "path": "/a/b/c", "value": "foo" }, | |||
{ "op": "remove", "path": "/a/b/c" }, | |||
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }, | |||
{ "op": "replace", "path": "/a/b/c", "value": 42 }, | |||
{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" }, | |||
{ "op": "copy", "from": "/a/b/d", "path": "/a/b/e" } | |||
] | |||
</syntaxhighlight> | |||
Evaluation of a JSON Patch document begins agains a target JSON document. Operations are applied sequentially, in the order in they appear in the array. Evaluation continues until all operations succeed or an error occurs. | |||
Also | =Also See= | ||
{{Internal|JSON Merge Patch|JSON Merge Patch}}{{Internal|Kubernetes Strategic Merge Patch|Kubernetes Strategic Merge Patch}} | |||
=Example= | |||
* [[Kubectl_patch#JSON_Patch_Usage_Examples|Using kubectl patch with JSON patch]] |
Latest revision as of 19:30, 29 July 2021
External
- https://tools.ietf.org/html/rfc6902
- https://erosb.github.io/post/json-patch-vs-merge-patch/
- https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/
Internal
Overview
JSON patch is defined in RFC6902.
JSON patch defines a JSON document structure for expressing a sequence of operations to apply to a JSON document, in order to change it. The format is suitable to use with the HTTP PATCH method and an "application/json-patch+json" media type.
PATCH /my/data HTTP/1.1
Host: example.org
Content-Length: 326
Content-Type: application/json-patch+json
If-Match: "abc123"
[
{ "op": "test", "path": "/a/b/c", "value": "foo" },
{ "op": "remove", "path": "/a/b/c" },
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
{ "op": "replace", "path": "/a/b/c", "value": 42 },
{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
{ "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
]
Evaluation of a JSON Patch document begins agains a target JSON document. Operations are applied sequentially, in the order in they appear in the array. Evaluation continues until all operations succeed or an error occurs.