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

JSON Patch update nested object

I'm been trying to use replace values within a nested object using JSON Patch, however I feel like I'm not getting the notation correct. Any ideas what the path should be? I've created the following code to prove it in LINQPad 6. void Main() { …
wonea
  • 4,783
  • 17
  • 86
  • 139
4
votes
0 answers

C# JSON Patch define rules on which fields can be updated

I have a JSON PATCH endpoint in my API, but I don't want to allow all properties to be edited and eventually need to do specific actions when a property has changed. I am having some trouble finding the best solution to achieve this. Running NET…
Menno
  • 142
  • 8
4
votes
0 answers

C# NET Core JsonPatchDocument dynamic instantiation of null properties

Guys consider the following problem we have supporting patch in our Microservice. We currently have nested models like this: TopModel { Model Model1 {get; set;} } Model { SomeData Data1 {get; set;} } If I want to patch Data1 and the Model1…
kh25
  • 1,238
  • 1
  • 15
  • 33
4
votes
2 answers

C# HttpClient returns 415 Unsupported media type on Patch request

We have a .netcore 3.1 ApiController with an endpoint listening for PATCH requests, and defined a Test Server that we're using for the Integration/API tests. PATCH request sent with Postman works just fine, but requests sent via HttpClient inside…
4
votes
1 answer

Convert JSON-Patch to MarkLogic JSON patch specification?

The JSON patch specification used by MarkLogic PATCH API is remarkably similar to the JSON-Path standard (RFC 6902) but not exactly the same. For example, to add a node to the following document: { "parent": { "child1": "c1-value", …
Fan Li
  • 1,057
  • 7
  • 11
4
votes
1 answer

JsonPatchDocument onto a complex Entity Framework tracked object

I am trying to use Json patches to update entities stored in an Entity Framework data context. I have entity classes like so - public class Customer { public Guid Id { get; set; } public string Name { get; set; } public virtual…
Brendan
  • 3,415
  • 24
  • 26
4
votes
1 answer

Apply json patch to a Mongoengine document

I'm trying to apply a json-patch to a Mongoengine Document. I'm using these json-patch library: https://github.com/stefankoegl/python-json-patch and mongoengine 0.14.3 with python 3.6.3 This is my actual code: json_patch =…
lukakiro
  • 61
  • 1
  • 8
4
votes
0 answers

JsonPatch in an Angular/.NET Web API project

I'm utilizing KevinDockx's JsonPatch extension for Visual Studio. My project uses .NET Web API (not Core) and Angular (6). .Net Web API doesn't support the JsonPatchDocument namespace, thus the need for KevinDock's JsonPatch extension. I'm reading…
Kyle Vassella
  • 2,296
  • 10
  • 32
  • 62
4
votes
1 answer

SnakeCaseNamingStrategy and JsonPatch in ASP.NET Core

Is there a way to register/use a "global" ContractResolver when using the the ApsNetCore.JsonPatch (2.1.1) package? I ran into an issue where the path was not resolved because the properties in my Models are in PascalCase but the path in the…
Edub
  • 508
  • 7
  • 24
4
votes
2 answers

asp.net - How to get / deserialize object of JsonPatchDocument?

I could serialize the JsonPatchDocument model by using JsonConvert.SerializeObject(), but the type of result is string, how can I convert it to normal array type? Or how to get JsonPatchDocument object straight to array? var pathSerialized =…
Hoàng Nguyễn
  • 1,121
  • 3
  • 33
  • 57
4
votes
0 answers

Retrofit2 - How to execute a JSON Patch Request (RFC 6902)

As of Retrofit2 2.3.0 there seems to be no built in functionality to execute a JSON Patch Request (as defined in RFC 6902. Also, see http://jsonpatch.com/ for some examples). Using the available @PATCH annotation, the full blown object is sent with…
wegenmic
  • 320
  • 1
  • 3
  • 13
4
votes
0 answers

Json Patch Request using Volley Android

I have the following code. ObjectMapper mapper = new ObjectMapper(); JsonNode source = mapper.readTree(oldJson); JsonNode target = mapper.readTree(newJson); JsonPatch patch = JsonDiff.asJsonPatch(source,target); Now how can I send this patch object…
Adroid007
  • 41
  • 1
4
votes
1 answer

How to update a collection using json patch

I can't find samples on the way to use JSON Patch to update a collection. In fact, I want to use a method PATCH on a collection REST resource in order to update the associated collection without sending again the whole collection. I wonder if JSON…
Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
4
votes
2 answers

Is json-patch supported in restclient?

I am having trouble in using POST method and JSON-Patch operations (Please refer to RFC: https://www.rfc-editor.org/rfc/rfc6902) in RestSharp's RestClient. AddBody() contains something like this: request.AddBody(new { op = "add", path =…
user3231144
  • 51
  • 1
  • 4
3
votes
1 answer

Convert JsonPatchDocument to string C#

I am using Newtonsoft.Json.JsonConvert.SerializeObject to convert a JsonPatchDocument to string but it's value property (which is in JObject format) doesn't seem to be converted to string. Here is what it looks like: Here is the JSON I am using…
Serhat
  • 216
  • 2
  • 17
1 2
3
12 13