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

Restrict fields from being changed by json-patch

Is there a way to restrict (or only allow) certain fields from being altered by a json-patch method? Is this even a desired feature of HTTP PATCH? I could not find anything (neither positive nor negative) in the respective rfc-5789 documentation I'm…
ch1ll
  • 419
  • 7
  • 20
0
votes
0 answers

Generate JSON from two different JSON objects without coding custom logic

I have a requirement where an event will emit a JSON following a defined schema = JSON-EventA schema. I have a config(config.json) that follows another JSON-EventB schema. Using data from JSON-EventA and Config from config.json, I have to generate a…
0
votes
1 answer

PATCH request losing body on IIS but not on localhost

I have a web API, where I'm trying to support a PATCH request with a JSON Patch body to make changes to an object on the server. I am using ASP Core with .Net 6, hosting using IIS on my web host. This is the controller method: public class…
Tony
  • 438
  • 1
  • 4
  • 10
0
votes
1 answer

How to do a JSON_MERGE_PATCH with Knex.js (MySQL)?

Newer MySQL versions (as well as SQLite and other databases supported by Knex.js) offer a great way to partially update JSON columns: JSON_MERGE_PATCH (aka JSON_PATCH in SQLite). As far as I can tell, Knex.js doesn't offer this functionality. One…
kgaspard
  • 302
  • 2
  • 10
0
votes
1 answer

Is there a way to update items in an array with JsonPatch?

The API to be invoked uses JsonPatch. The following is a sample JSON. { "hello": false , "array1": [ { "subarray": [ "k2", "k1"] } , { "subarray": [ "k1"] } ] } I would like to update both the subarrays (elements of the…
Khanna111
  • 3,627
  • 1
  • 23
  • 25
0
votes
0 answers

How to patch (update) asynchronous in asp.net core (with JsonPatch, NewtonsoftJson)

I have this action method, I want to update the movie throw patching and there is not a method like ApplyTo[Async], what can I do ? [HttpPatch("{id}/edit")] public async Task EditMoviePatchAsync([FromRoute] int id, [FromBody]…
0
votes
0 answers

JSON patch not working with abstract classes (inheritance)

I am trying to use JSON patch in my .net core project to update data. I am using Table-per-type in my architecture for this particular feature. So my models are like this. I have a form model public class HrFormV1 { public HrFormV1() { …
mohsinali1317
  • 4,255
  • 9
  • 46
  • 85
0
votes
1 answer

How to edit or delete an item from a collection using HTTP PATCH (JSON PATCH)

I want to be able to patch an item that consist of multiple properties, some of them are collections of classes. For now, I do not have any collection in the child classes, but potentially they can be added later. For deleting an item with json…
Mykola
  • 197
  • 1
  • 10
0
votes
2 answers

How to get actual value from object of JsonPatchDocument in C#?

I have one payload like below to update via patch call in webAPI. [ { "value": [ { "Id": "12", "name": "ABC" }, { "Id": "89", "name": "XYZ" } ], "path": "/basepathofemployee", …
Abhishek
  • 85
  • 1
  • 9
0
votes
1 answer

Perform side effect after Json Patch

Currently have an asp.net web api and implementing JSON Patch using AspNetCore.JsonPatch and want to perform a side effect if a certain action is done via Json patch? E.g. patch request to update an array is done then triggers another function to be…
John_Mason27
  • 227
  • 4
  • 17
0
votes
1 answer

Add new operations to existing jsonpatch file

I'm working on a test suite for some Java code that uses jsonpatch to modify db entries. What I am trying to do is have a template jsonpatch request saved down as a file that individual unit tests could read from, modify some operations, and then…
5E4ME
  • 173
  • 4
  • 16
0
votes
2 answers

AzureDevOps - Creating WorkItem via JsonPatchOperation

To create a workitem I need to specify its fields but where exactly can I see all the possible "field paths" on my AzureDevOps site? I've edited an existing workitem and added some more fields to it but I cant seem to find the needed "field path"…
0
votes
1 answer

Should JSON patch fail when an array or object isn't defined?

Given the JSON object { "property": "value" } If you perform a JSON patch on this object like the following [{ "op": "add", "path": "/otherProperty/property", "value": "childvalue" }] Should the JSON patch operation fail because the…
gislikonrad
  • 3,401
  • 2
  • 22
  • 24
0
votes
1 answer

Using fast-json-patched for document versioning and timelining

I'm attempting to create a revisable document, with the edits stored as fast-json-patched objects. The rough outline is : const jsonpatch = require('fast-json-patch'); /** * Generate a doc, with all the state changes recorded as * diffed…
Dycey
  • 4,767
  • 5
  • 47
  • 86
0
votes
1 answer

Json Patch - does it violate REST rules?

Does Json Patch violate REST rules? My API won't be RESTful if I use it? Or, maybe not? { "op": "replace", "path": "/biscuits/0/name", "value": "Chocolate Digestive" }