Jump to content

JSON Patch

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mackiovello (talk | contribs) at 18:06, 4 December 2016. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

JSON Patch is a web standard format for describing changes in a JSON document. It is meant to be used together with HTTP Patch which allows for the modification of an existing HTTP resource. The JSON Patch media type is application/json-patch + json.

A JSON Patch document is structured as a JSON array of objects where each object contains one of the six JSON Patch operations: add, remove, replace, move, copy, and test. The syntax looks like this:[1][2]

[
    { "op": "add", "path": "/myPath", "value": ["myValue"] }
]

The operations does as follows:

Add: add a value into an object or array.

Remove: remove a value from an object or array.

Replace: replaces a value. Logically identical to using remove and then add.

Copy: copy a value from one path to another by adding the value at a specified to another location.

Move: moves a value from one place to another by removing from one location and adding to another.

Test: tests for equality at a certain path for a certain value.[3]

References

  1. ^ Mark, Nottingham,; Paul, Bryan,. "JavaScript Object Notation (JSON) Patch". tools.ietf.org. Retrieved 2016-12-04.{{cite web}}: CS1 maint: extra punctuation (link) CS1 maint: multiple names: authors list (link)
  2. ^ "mnot's blog: Why PATCH is Good for Your HTTP API". www.mnot.net. Retrieved 2016-12-04.
  3. ^ Foster, Ben (11 April 2016). "How to perform partial resource updates with JSON Patch and ASP.NET Core". benfoster.io.