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
40
votes
1 answer

What is the difference between patches vs patchesJson6902 in Kustomize

Based on the docs that I've read, there are 3 methods of patching: patches patchesStrategicMerge patchesJson6902. The difference between patchesStrategicMerge and patchesJson6902 is obvious. patchesStrategicMerge requires a duplicate structure of…
Alex
  • 1,293
  • 1
  • 13
  • 26
30
votes
2 answers

What is the JSON Patch format to remove an element from an array?

I have the following JSON document, from which I want to remove the "roleId2" element from the "roles" field's array value: { "id" : 12345, "firstName": "SomeFirstName", "lastName": "SomeLastName", "roles":["roleId1", "roleId2",…
Niranjan
  • 2,601
  • 8
  • 43
  • 54
29
votes
3 answers

How can I create a JsonPatchDocument from comparing two c# objects?

Given I have two c# objects of the same type, I want to compare them to create a JsonPatchDocument. I have a StyleDetail class defined like this: public class StyleDetail { public string Id { get; set; } public string Code {…
jmc
  • 1,058
  • 1
  • 12
  • 20
25
votes
3 answers

Generate JSON-patch from two objects

Given two Javascript objects (A and B), is there a way to generate the JSON patch, so that when that patch is applied to A it would change the object's properties to that of object B? For example, given hypothetical JSONPatch function (perhaps being…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
19
votes
2 answers

jsonpatch path to update array object by object ID

I am trying to figure out the best way to patch a collection of objects. I am trying to change the sort order of a number of objects and was thinking jsonpatch may be the right approach. My Object Looks Like: [ { "ID": "100", …
JoAMoS
  • 1,459
  • 3
  • 18
  • 27
16
votes
4 answers

PATCH when working with DTO

I'm working on asp.net core webAPi and EF core, and want to implement "update" operation (partially edit entity). I searched the correct way to deal with that, and saw that I should use jsonPatch. the problem is that I'm expose just DTOs through my…
arielorvits
  • 5,235
  • 8
  • 36
  • 61
15
votes
2 answers

Using JSON Patch to add values to a dictionary

Overview I'm trying to write a web service using ASP.NET Core that allows clients to query and modify the state of a microcontroller. This microcontroller contains a number of systems that I model within my application - for instance, a PWM system,…
Tagc
  • 8,736
  • 7
  • 61
  • 114
13
votes
2 answers

jsonpatch adding element to array and creating it if not exist

I'm trying to append an element to an array. But i cannot ensure that the array alread exists. So it should be created if not. This example works: Source json: { "data": [] } Patch doc: [{ "op":"add", "path":"/data/-", "value":…
nblum
  • 155
  • 1
  • 1
  • 6
13
votes
2 answers

Securing JSON-PATCH paths in Spring Boot Data Rest application

I'm using a pretty vanilla spring-boot-starter-data-rest setup and enabled the PATCH method. All is working, but I have a security concern and wonder what's the recommended way of mitigating it. The problem is that PATCH paths allow reachable…
sofend
  • 647
  • 8
  • 17
12
votes
3 answers

Getting 'TypeError: Failed to fetch' error when trying to call AspNetCore Restful API from Blazor Wasm

I'm getting a 'TypeError: Failed to fetch' error when trying to call my AspNetCore Restful API from Blazor Wasm. I can call it from Postman, and it works fine. My Environment: Microsoft Visual Studio Community 2019 Preview Version 16.6.0 Preview…
12
votes
3 answers

JSON Patch Request validation in Java

In my spring boot service, I'm using https://github.com/java-json-tools/json-patch for handling PATCH requests. Everything seems to be ok except a way to avoid modifying immutable fields like object id's, creation_time etc. I have found a similar…
shoaib1992
  • 410
  • 1
  • 8
  • 26
11
votes
3 answers

How can I merge two JSON objects with Rust?

I have two JSON files: JSON 1 { "title": "This is a title", "person" : { "firstName" : "John", "lastName" : "Doe" }, "cities":[ "london", "paris" ] } JSON 2 { "title": "This is another title", "person" : { "firstName" :…
Harindaka
  • 4,658
  • 8
  • 43
  • 62
11
votes
1 answer

Modify @OneToMany entity in Spring Data Rest without its repository

In my project I use object of type A which has OneToMany relation (orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER) to objects of type B. I need SpringDataRest (SDR) to store complete full A object with its B objects…
rotmajster
  • 111
  • 1
  • 6
10
votes
2 answers

How to use fast-json-patch in Angular 2 applications?

I want to use the "fast-json-patch" library (https://github.com/Starcounter-Jack/JSON-Patch) in an Angular 2 application. I have tried adding: 'fast-json-patch': 'vendor/fast-json-patch/dist/json-patch-duplex.min.js' in the system-config.ts file…
Rocky
  • 391
  • 5
  • 14
10
votes
1 answer

Purpose of tilde in JSON Pointer

The JSON Pointer spec states: the characters '~' (%x7E) and '/' (%x2F) have special meanings in JSON Pointer It is clear what '/' is used for, but I see no indication of what purpose the tilde serves (only mention that it needs to be escaped…
Brett Zamir
  • 14,034
  • 6
  • 54
  • 77
1
2 3
12 13