Questions tagged [json-patch]

JSON Patch defines the media type "application/json-patch", a JSON document structure for expressing a sequence of operations to apply to a JSON document

  1. Introduction

    JavaScript Object Notation (JSON) [RFC4627] is a common format for the exchange and storage of structured data. HTTP PATCH [RFC5789] extends the Hypertext Transfer Protocol (HTTP) [RFC2616] with a method to perform partial modifications to resources.

    JSON Patch is a format (identified by the media type "application/ json-patch") for expressing a sequence of operations to apply to a target JSON document, suitable for use with the HTTP PATCH method.

    This format is also potentially useful in other cases where necessary to make partial updates to a JSON document, or to a data structure that has similar constraints (i.e., they can be serialised as an object or an array using the JSON grammar).

  2. Conventions

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].

    See Section 5 for information about handling errors.

  3. Document Structure

    A JSON Patch document is a JSON [RFC4627] document that represents an array of objects. Each object represents a single operation to be applied to the target JSON document.

    An example JSON Patch document, transferred in a HTTP PATCH request:

    PATCH /my/data HTTP/1.1 Host: example.org Content-Length: 326 Content-Type: application/json-patch 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" } ]

Bryan & Nottingham Expires July 24, 2013 [Page 3]

Internet-Draft JSON Patch January 2013

Evaluation of a JSON Patch document begins against a target JSON document. Operations are applied sequentially in the order they appear in the array. Each operation in the sequence is applied to the target document; the resulting document becomes the target of the next operation. Evaluation continues until all operations are successfully applied, or an error condition is encountered. Sources:

http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-10

191 questions
1
vote
1 answer

JSON Patch and "aggregate" DTOs

A somewhat contrived, but nonetheless important, example. Assume the following case whereby UserDetails is an aggregate DTO (not sure of correct terminology, please educate me, but basically a model of collected information from different…
Mardoxx
  • 4,372
  • 7
  • 41
  • 67
1
vote
1 answer

JSON-Patch 'remove' with empty path - What is the official, standard outcome?

What is the standard outcome of the following 'remove' JSON Patch with an empty "" path? [{ "op": "remove", "path": ""}] Should it clear the whole object, equal to assigning {}? In http://jsonpatch.com/ it says: To point to the root of the document…
Kris
  • 4,595
  • 7
  • 32
  • 50
1
vote
3 answers

JSON to JSON Transform of input sample using any existing java library/tools

Input: { "Student": { "name" :"abc", "id" : 588, "class : "12" } } Reqired Output: { "Student": { "key" :"name", "value":"abc", "key" :"id", "value":"588", "key" :"class", …
bigdata
  • 21
  • 7
1
vote
0 answers

What is the most efficient way to patch a JSON patch?

Say, I have this JSON patch, which adds something into the groups array [ {"op":"add","path":"/food/groups/-", "value":{ "select" : 55, "pool" : [ [ 0.111, "biscuit" ], [ 0.111, "cookie" ], …
deathlock
  • 2,756
  • 5
  • 27
  • 48
1
vote
2 answers

HTTP ReST: update large collections: better approach than JSON PATCH?

I am designing a web service to regularly receive updates to lists. At this point, a list can still be modeled as a single entity (/lists/myList) or an actual collection with many resources (/lists/myList/entries/). The lists are large (millions…
Tomas Creemers
  • 2,645
  • 14
  • 15
1
vote
1 answer

Json Patch removing sub elements in an array

I want to remove sub elements from an array for example { "employees": [ { "name": "name1", "id": "id1" }, { "name": "name2", "id": "id2" }, { …
user2454514
1
vote
1 answer

Using jsonpatch to create new path

I'm trying to use jsonpatch to create new path in a mongoose document, but I can't make it work. The page oficial page enter link description here says that I can add new values to a path like this, {op: add, path:/mypath, value: 'new value'} But…
Diego
  • 493
  • 1
  • 9
  • 26
1
vote
1 answer

Unsupported Media Type error when using json-patch in Ramone

Update: I downloaded Ramone project, added it to my project and then ran the application again with debugger. The error is shown below: public MediaTypeWriterRegistration GetWriter(Type t, MediaType mediaType) { ... CodecEntry entry =…
user3231144
  • 51
  • 1
  • 4
0
votes
0 answers

JsonPatch remove command when value changed from null to undefined

Server returns data that may include optional text values. In the original object they appear as null. I have dynamic form (using React + Ant Design) which allows user to add more of these fields. When I save the form, the form returns the field as…
syydi
  • 119
  • 2
  • 13
0
votes
1 answer

Compressing a list of JSON patches

What type of data structure can help compress JSON patches? We can compress JSON patches by removing redundant patches. Redundant patches are patches which are fully replaced later, either by a patch with the same path, or with a patch with a…
Sentient
  • 781
  • 2
  • 10
  • 23
0
votes
0 answers

Securely deleting a list item by jsonpatch (refernce by element id)

I have developed a restapi using SpringBoot. I would now like implements object manipulation by jsonpatch. In general, I would like the restrict the patch to certain properties. For example, in addition to my Person Dto, I also have a PersonPatch…
Helotrix
  • 101
  • 1
  • 6
0
votes
0 answers

Remove operation in JsonPatch builds an incorrect path with duplicate indexes for arrays

Basically the same issue as in - https://github.com/flipkart-incubator/zjsonpatch/issues/121 Is there a way to overcome this or Is there any alternate to JsonPatch library which gives the diff of 2 jsons similar to JsonPatch but with correct…
0
votes
0 answers

Why json-patch changing the Date format

I am using json patch 1.13 version to apply patch on my json payload . This is the POM Entry using for json patch com.github.java-json-tools json-patch
VKP
  • 589
  • 1
  • 8
  • 34
0
votes
1 answer

Removing multiple elements from an array using JSON patch

Say I have an entity that looks like this: { "list": ["foo", "qux", "bar"] } If I want to remove "foo" and "bar" using one JSON patch with two operations. What is the correct syntax? Option 1 This option expects the indexes to be immutable while…
gislikonrad
  • 3,401
  • 2
  • 22
  • 24
0
votes
0 answers

AutoMapper and JsonPatchDocument's operation paths

We are using .NET Core 3.1, Microsoft.AspNetCore.JsonPatch 3.1.27 and AutoMapper 12.0.1. We are developing a REST API. It exposes some endpoints for updating entities with HTTP PATCH verb. These controller actions accept JSON patch document of DTO…
Sam Carlson
  • 1,891
  • 1
  • 17
  • 44