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

Get JsonPatchDocument operations from an original JSon and an actual JSon

I want to obtain all the operations during comparison of an original json and the actual json. The normal use of JsonPatchDocument is to apply operation on an expandoObject to create a json. I want the reverse, and there is no tool for that. In…
Guillaume V
  • 931
  • 2
  • 10
  • 27
2
votes
1 answer

Update nested elements using ASP.NET core with json patch

Anybody know how to update nested elements of items using asp.net core json patch? I'm tried to use xx.Operations.Add(new Operation("Replace", $"schedules/{scheduleId}/status", null, DataRequestStatusEnum.ExtractionFailed)); But…
cortisol
  • 335
  • 2
  • 18
2
votes
0 answers

Handle file upload in RFC 6902 Json Patch

I'm working on a application in which users can update their information. For the moment, RFC 6902 Json-patch is used to update textual information (firstname, lastname, phone...) via a basic HTML Form. User can now add images to their profile. Is…
Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80
2
votes
0 answers

ClassCastException for the same class type in Spring-sync

I'm using Spring-sync as an implementation of RFC 6902 (JSON Patch). The client side sends me a JsonNode representing the operations to apply on the server object. My code is as following : @PatchMapping(path = "/profile/{userId}") public…
Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80
2
votes
0 answers

JsonPatch to preserve naming of properties (camel-cased)

I am using Microsoft.AspNetCore.JsonPatch which I've added via NuGet from here and got stuck when trying to match my properties back on API-side. Is there any way to preserve the camel-case naming of my properties when serializing/deserializing. My…
KingKerosin
  • 3,639
  • 4
  • 38
  • 77
2
votes
1 answer

Validating Mongoose Array Updates with JSON Patch

I am currently building an API which uses the JSON patch specification to do partial updates to MongoDB using the Mongoose ORM. I am using the node module mongoose-json-patch to apply patches to my documents like so: var patchUpdate =…
lattice
  • 35
  • 1
  • 6
2
votes
1 answer

Is there any way to preserve the order while generating patch for json files ?

I am new to Json stuff i.e. JSON PATCH. I have scenario where I need to figure out between two version of Json files of same object, for that I am using json-patch-master. But unfortunately the patch generated interpreting it differently…
BdEngineer
  • 2,929
  • 4
  • 49
  • 85
2
votes
1 answer

Use of JSON-PATCH format

I have a question regarding the JSON-PATCH format specified in RFC6902. As I understand this format good for PATCH requests. Is there a way of using this in the response, may be using partial content code? I have a special case in which operations…
Sajith
  • 106
  • 5
1
vote
1 answer

Validate JsonPatchDocument request operations before applying it in .NET Core

I need to validate the JsonPatchDocument which is coming in the request before applying it to my object. public async Task UpdateUserByIdAsync([Required][StringLength(40)] string id, [Required][FromBody] JsonPatchDocument
Amir Suhel
  • 33
  • 4
1
vote
0 answers

Is there an algorithm to get the optimal json patch?

I'm trying to use this json patch implementation to create patch https://github.com/stefankoegl/python-json-patch JsonPatch RFC But I found the result in some cases not satisfactory. For example json 1 [ { "asset": "USDT", …
Xiaoyong Guo
  • 361
  • 1
  • 7
1
vote
1 answer

Is it possible to configure Entity Framework Core >= 7.0 to use List instead of HashSet by configuration?

Entity Framework >= 7.0 provides HashSet as implementation to 1-n and m-n associations (i.e. collections). In my case, these associations are typed as ICollection, and HashSet doesn't work for me, because JSON PATCH (RFC 6902) standard, it…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
1
vote
0 answers

How to construct Json-patch payload to call PATCH endpoint

Library used: com.github.fge.jsonpatch And I have one PATCH endpoint which accepts the String of json-patch operations. public Employee patchEmployee(String patchOperations, String empId); This method then does the required conversion to JsonPatch…
Arthur
  • 87
  • 6
1
vote
2 answers

Returning JSON arrary with particular property using Postgres

I have a JSONB data stored in a column called data in table nftdata. Inside this JSON data (as shown below) there is a JSON array at result.data.items. This is an array of 2400 JSON objects but I have shown two here as an example: { …
Laniakea
  • 25
  • 4
1
vote
2 answers

Kustomize best practice to apply the same patch to multiple base files

I have an application with different versions. The base resource file for each version is slightly different. But the patch which needs to be applied to the base file is same. What should be the best structure to apply the same patch to different…
JoyceLee
  • 85
  • 3
  • 11
1
vote
1 answer

C# JsonPatchDocument: Is it possible to set custom error messages when ModelState is invalid

When for example an invalid date has been entered the response message will be the following. { "errors": { "AccountDto": [ "The value '77-77-7777' is invalid for target location." ] }, "title": "One or…
user3261212
  • 391
  • 2
  • 15