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

JsonPatchDocument instantiate nested object if null

I have a data model like this: Student { public string Name {get; set;} public Address address {get; set;} } Address { public string City {get; set;} public int Postcode {get; set;} } And I have the following data: Student1…
Manh Quang
  • 91
  • 1
  • 9
0
votes
0 answers

Post a json patch in Swift 5

I'm testing an api call in Swift with Patch to update an object partially. It worked well with Postman PATCH http://localhost:5000/api/accounts/eca9c1b05fb24ca192afe370aa5a1965 [ { "op": "add", "path": "/firstname", …
asusu
  • 15
  • 5
0
votes
1 answer

How to get property level serialization error while using JsonPatchDocument in .NET Core WebApi during PATCH calls

I am implementing HTTP Patch using JsonPatch library from .NET Core.(Microsoft.AspNetCore.Mvc.NewtonsoftJson). MS Doc: https://learn.microsoft.com/en-us/aspnet/core/web-api/jsonpatch?view=aspnetcore-5.0 Am able to do partial updates using JsonPatch…
0
votes
1 answer

JSON Patch 'replace' entire list of strings

I am having trouble performing an update using JSON Patch. In this case, I am trying to replace the entire collection of strings ('Names'). public class NamesUpdate { public List Names { get; } = new List(); } public void…
user3037172
  • 577
  • 1
  • 7
  • 25
0
votes
1 answer

How to apply partial ModelState validation for JsonPatch in ASP.NET Core

I was struggling with an issue that if you use data annotations for model validation in ASP.NET Core and you run patchDoc.ApplyTo(newData); and then if (!TryValidateModel(newData)) you got model validation errors for operations not included in the…
0
votes
1 answer

JSON-RPC vs JSON Patch

There are a lot of comparisons like "REST vs smth" (eg vs Kafka, vs JSON-RPC), but I also see many similarities between JSON-RPC and JSON Patch – both of them specify operation/method, values/parameters, and allow to perform batch requests. The only…
AivanF.
  • 1,134
  • 2
  • 23
  • 52
0
votes
1 answer

How do I pass along json patch data with rest client in asp.net?

We use a rest api to get customer information. A lot of the GET request were already written by others. I was able to follow their code to create other GET request, but one of the API methods for updating a customer requires using json patch. …
DaGap
  • 23
  • 6
0
votes
2 answers

Ignore JsonPatch specific property

I am currently trying to figure out how I could prevent the user of my API to change/update a specific property. From what I was able to gather from the web was that it is simply not supported, at least by the Microsoft implementation…
Twenty
  • 5,234
  • 4
  • 32
  • 67
0
votes
2 answers

HttpPatch operation with JsonPatchDocument and dynamic objects issue

struggling with the following, using this example: https://github.com/dotnet/AspNetCore.Docs/blob/8793347c90ba83166c0efc6cb5fbae60a0e063a7/aspnetcore/web-api/jsonpatch/samples/3.1/api/Controllers/HomeController.cs I am having a controller with patch…
Kris
  • 322
  • 8
  • 19
0
votes
1 answer

Json Patch: Append multiple?

Basically, how can I can combine these two operations? - op: add path: /spec/template/spec/volumes/- value: name: php-src emptyDir: {} - op: add path: /spec/template/spec/volumes/- value: name: nginx-src emptyDir: {} If I…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
0
votes
2 answers

Why is this element returning undefined in the form when I attempt to edit it, but displaying correctly in debugger and console.log?

I keep getting thrown this error: "Cannot read property 'textContent' of undefined at HTMLDocument". This error occurs when dogName,dogBreed and dogSex and set within the 'click' listener. I am able to click the button and render the information,…
st123
  • 246
  • 3
  • 14
0
votes
1 answer

Need to add a list of in JSON via JSON Patch

I have been reading about JSON Patch. However, I cannot find a solution to my problem. I have a JSON which I need to add a list. For example: { "orders": "food" } I need to inject this list of items below the orders attribute. { "items": [ { …
Yejin
  • 541
  • 2
  • 15
  • 32
0
votes
1 answer

Is there JsonPatch analog for filtering json data?

I need to construct complex query to json like "field name is Bob and field age less then 40 or salary more or equal 40000" For patch json data I can use JsonPatch, but is there any format for filtering json data?
VoidName
  • 340
  • 2
  • 16
0
votes
2 answers

How to disallow updating of a field while patching with Java JSON Patch

I have a spring boot project containing a Pojo named Person and a controller which allows a user to get a person by Id and to Patch the Person object so that it's name or/and surname could be updated. The Person Pojo (simplified for example…
Maria Stellini
  • 359
  • 1
  • 3
  • 15
0
votes
0 answers

Creating a Node.js service for PostgreSQL: a json-patch runner

Having: Some json-patch objects A jsonb field in a PostgreSQL database How to have a node.js code which take as input json-patch objects and which the output is SQL request that apply json-patches to database. May I have to create this from…
Slim
  • 1,256
  • 1
  • 13
  • 25