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

How to use or configure Json Patch with collections and IDs in java

In java, is it possible to configure the Json patch to perform operation on collections using id object instead of position? for example: { "op": "replace", "path": "/collection/0/field", "value": test }, to: { "op": "replace", …
Michael Cauduro
  • 185
  • 1
  • 3
  • 16
1
vote
0 answers

How to implement JsonPatchDocument in .NET Framework 4.8

I am trying to implement JsonPatchDocument in .NET Framework 4.8, and the nuget package has installed successfully, and the code builds. But when I try to call an endpoint that accepts HTTP Patch, the JsonPatchDocument I get is null. I remember…
NollerNiller
  • 25
  • 1
  • 5
1
vote
2 answers

JSON Patch diffing fails due to ObjectMapper?

I have 2 objects that I'm trying to diff. For this purpose I use Jackson ObjectMapper in spring-boot version 2.1.3 to de-serialize them to a String, read them as a tree (convert to JsonNode) and then diff them to create a JsonPatch object. What I do…
linuxNoob
  • 600
  • 2
  • 14
  • 30
1
vote
0 answers

Visual representation for JSON Patch

I've developed a tool which creates JSON patch results in a .csv file specifying differences between two sets of JSON files. I want the business side of my organisation to be able to easily interpret this data and wondered if there is a UI or…
gsdev
  • 259
  • 4
  • 14
1
vote
1 answer

Testing JsonPatch in Spring Boot application

I'm trying out JsonPatch but ran into an issue when I try to test it. My REST controller looks like this: @RestController @RequestMapping("/v1/arbetsorder") class ArbetsorderController { @PatchMapping(path ="/tider/{tid-id}", consumes =…
1
vote
1 answer

Restrict JsonPatchDocument patch operations on a per member basis

Are there any recommendations for cases where you need some members to be immutable/read-only as far as patch operations are concerned? Normally we would pass a context entity to the JsonPatchDocument, we expose the entire object to modification bar…
1
vote
1 answer

Apply JSON Patch to a collection

I have a Spring Boot application in which I want to enable the JSON Patching of multiple resources at the same time, as described in this question. My endpoint accepts a javax.json.JsonPatch as parameter and returns 204 NO CONTENT upon success. Now,…
Daniel Pop
  • 456
  • 1
  • 6
  • 23
1
vote
1 answer

patch endpoint test using rest assured mock mvc

I am trying to write a test for patch end point using rest assured mock mvc. But i am not able to create an object of jsonmerge patch to place in the body of the mock.below is the end point for which i need to wrote the test @PatchMapping(path…
1
vote
0 answers

How patching an object with an array of objects

I have a many-to-many relationship between Ticket and ProductList . Here's is what I have for a Ticket : // INIT MODEL var ticketModel = new Ticket { Customer = new Customer(), …
harili
  • 406
  • 9
  • 24
1
vote
1 answer

JSONPatch escape slash '/' from JSONPatch+JSON

I've below JSON and I wanted to update few fields from it { "process": "my-process", "pod": "some-pod", "org": "some-org", "config": { "version": "436_601_83.0.0", "path": "companyName/ccg", …
Swapnil Kotwal
  • 5,418
  • 6
  • 48
  • 92
1
vote
1 answer

Get/Modify specific data from jsonPatch request

I need to modify JSONPatch before applying it to the main object, I search a lot but didn't find any solution. I have a JSONPatch request something like this: [op: replace; path: "/size"; value: "1", op: replace; path: "/name"; value: "test"] Now…
1
vote
0 answers

How can I use Json patch document using VB.net

I'm struggling to use the Add method for Json Patch Document in vb.net? My goal is to create work items programmatically. I'm looking to add values to Title, Description and Priority field of a work item. Do I have to use the same code separately…
Dev-Ops
  • 11
  • 2
1
vote
1 answer

Json Patch in Asp.net core api with cosmos db

Is it possible to use dotnet core api's HTTPPATCH / JSONPATCH with azure cosmos db? Is there any sample?
1
vote
0 answers

How to patch using JsonPatchDocument on DTO with multiple tables

I'm using ASP .Net Core. I have a DTO with 3 models of table from DB Scaffolding. public class StudentDTO { public int StudentId { get; set; } public Student StudentInfo { get; set; } public Address StudentAddressDetails { get; set; } …
user2782405
  • 393
  • 1
  • 6
  • 20
1
vote
1 answer

Mutating a Kubernetes deployment yaml for tolerations doc is missing

I created a mutating admission webhook in my Kubernetes cluster. The api mutation webhook adds tolerations to a Deployment YAML. However, it says an error Internal error occurred: jsonpatch add operation does not apply: doc is missing path:…
Yejin
  • 541
  • 2
  • 15
  • 32