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
3
votes
0 answers

zjsonpatch diff results in a flat format for add operation

I am trying to get the JSON diff using the zjsonpatch library. The library provides the results for add, remove and replace operations. The results are coming as expected. But for add operation, the values output is sometimes a map of key/value…
Vivek Narayanasetty
  • 522
  • 2
  • 5
  • 12
3
votes
1 answer

How to apply json-patch to plain json in .net core?

JsonPatchDocument.Apply method works on an object graph, but instead I want to apply a json patch to plain json. For example, suppose I have this json: { "name": "JSON Patch", "text": "OLD" } How can I apply a patch like this with C#? [ { "op":…
netcoredev
  • 33
  • 1
  • 4
3
votes
2 answers

JsonPatchDocument is null after migration to .Net Core 3

I have a AspNetCore-WebApi-Project with several patch-operations, which worked fine with Core 2.2. After migration to Core 3 the [FromBody] JsonPatchDocument is null. My Get/Post-Methods are still functioning as expected. This is one part of my…
Joshit
  • 1,238
  • 16
  • 38
3
votes
1 answer

GraphQL Mutation with JSON Patch

Are there any data types in GraphQL that can be used to describe a JSON Patch operation? The structure of a JSON Patch operation is as follows. { "op": "add|replace|remove", "path": "/hello", "value": ["world"] } Where value can be any valid JSON…
Brendan
  • 3,415
  • 24
  • 26
3
votes
2 answers

How to union-merge json child objects using json diff and merge?

I have two json files as such: json1 { "plans": { "buildings": [ { "floors": ["1" "2" "3" ] }, { "floors": ["1"] } ] } } json 2 { "plans": { "buildings": [ …
mohd.gadi
  • 495
  • 1
  • 7
  • 15
3
votes
2 answers

`kubectl patch` each element of array

I would like to patch all container templates in a Kubernetes deployment with a single kubectl patch command, without having to know their name. Is that possible? I know I am able to achieve the replacement through awk, sed, jq and kubectl replace,…
Dennis Stritzke
  • 5,198
  • 1
  • 19
  • 28
3
votes
1 answer

JsonPatchDocument not binding correctly

I'm trying to use JsonPatch in ASP.NET Core to handle partial updates for a model but am having binding issues when the PATCH is sent through to the Web API controller action: I'm using a small library to make the PATCH request: axios …
ajbeaven
  • 9,265
  • 13
  • 76
  • 121
3
votes
0 answers

Asp.Net Core JsonPatchDocument: How to inspect operations server-side?

I'm just starting with PATCH requests in Asp.NET core with JsonPatchDocument. This class has the cool feature that I can add Operations like: patchDoc.Replace(i=>i.IntegerProperty, 3); patchDoc.Replace(i=>i.AnotherProperty,…
Volker
  • 1,753
  • 2
  • 18
  • 28
3
votes
2 answers

How to Update Model in ASP NET MVC 6?

Scenario: How to update a model? ASP MVC 6 I am trying to update a model. For passing the model information to the client(browser/app) I am using the DTO. Question 1: For updating, should I post the whole object back? Question 2: Is there a way I…
Rahul Kushwaha
  • 421
  • 7
  • 14
3
votes
4 answers

Parsing Nested JSON in java without know structure of JSON?

I am Trying to parse nested JSON, But i don't know the format of JSON...I want all the Keys and Values of JSON. Example: { "txnSpecificData1": "11", "txnSpecificData2": "21", "merchantData": { "merchantSpecificData1": "111", …
user2888996
  • 417
  • 8
  • 20
3
votes
1 answer

JSON Patch - Java Implementation for an object

I am new to JSON Patch and I have gone through many reference materials but I am not sure what is the best and simple approach to implement JSON Patch to an Object (JSON Model). In my case, I am trying to implement JSON Patch to my Spring based REST…
Zubair Ahmed
  • 147
  • 4
  • 13
3
votes
1 answer

Is RethinkDB useful on partial updating json documents according rfc6902?

Please share your experience with partial updating of JSON document.At now I'm storing my JSON documents in MongoDB which looks like the following: { id: ObjectId(507f191e810c19729de860ea), title: 'Sterling Archer', comments: [ {text:…
Erik
  • 14,060
  • 49
  • 132
  • 218
3
votes
1 answer

JSON patch rfc6902: Sequential operation and index

In JSON patch, how should one use the index for subsequent operation on the same array. For example, consider var source = { colors: ['Red', 'Green', 'Blue'] }; var target = { colors: [] }; patch doc…
bsr
  • 57,282
  • 86
  • 216
  • 316
2
votes
1 answer

Distinguish between NULL and not present using JSON Merge Patch with NetCore WebApi and System.Text.Json

I want to support partial updates with JSON Merge Patch. The domain model is based on the always valid concept and has no public setters. Therefore I can't just apply the changes to the class types. I need to translate the changes to the specific…
M. Koch
  • 525
  • 4
  • 20
2
votes
1 answer

How to convert String to JsonPatch?

Java String which I retrieved from the database: [ { "op": "replace", "path": "/baz", "value": "boo" }, { "op": "add", "path": "/hello", "value": ["world"] }, { "op": "remove", "path": "/foo" } ] How can I convert it to a JsonPatch object? I…
Ayush
  • 206
  • 7
  • 22