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

Add multiple values to array in single JSON Patch operation?

I have a json object like this: { "content" : [ { "id" : 54 "foo" : "bar" }, { "id" : 43 "foo" : "bar" }, { "id" : 76 "foo" : "bar" …
Blasterdude8
  • 101
  • 1
  • 5
9
votes
4 answers

JSON Patch Validation .Net Core

Has anyone found a good way to use data annotations to prevent specifc properties from being updated in a json patch doc. Model: public class Entity { [DoNotAllowPatchUpdate] public string Id { get; set; } public string Name {…
Hizzy
  • 741
  • 7
  • 27
8
votes
1 answer

json-patch wildcard usage in argocd manifest

Is it possible to replace this --- apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: elastic-operator labels: argocd.application.type: "system" spec: ignoreDifferences: - group: admissionregistration.k8s.io kind:…
carrotcakeslayer
  • 809
  • 2
  • 9
  • 33
8
votes
4 answers

How to use ModelState with JsonPatchDocument.Applyto

I see in the Microsoft docs and many examples where they call JsonPatchDocument.ApplyTo(patchObject, ModelState), but I can't seem to get it to build that way. I get a build error saying "Error CS1503 Argument 2: cannot convert from…
Shane
  • 83
  • 1
  • 4
8
votes
2 answers

Spring Data Rest - PATCH Postgres jsonb field

The short version is: How to patch the JSON object contained in a Postgres jsonb field using Spring Data Rest PATCH method? Here comes the long version, please consider the following entity: @Entity @Table(name = "examples") public class Example { …
Anthony Drogon
  • 1,704
  • 1
  • 17
  • 24
7
votes
4 answers

How can I create a GraphQL partial update with HotChocolate and EFCore

I am trying to create an ASP.NET Core 3.1 application using Entity Framework Core and Hot Chocolate. The application needs to support creating, querying, updating and deleting objects through GraphQL. Some fields are required to have…
Alban
  • 163
  • 1
  • 8
7
votes
0 answers

Exception on JSON-PATCH post to @RepositoryRestResource in Spring Data REST

I can't get Spring Data REST to accept a JSON-PATCH content body, what am I doing wrong? Simple domain: @Document public class DomainA { @Id private String id; private String atext; public String getAtext(){ return atext;} public…
Wayne
  • 1,075
  • 1
  • 10
  • 21
6
votes
1 answer

Using VsConnection WorkItemTrackingHttpClient patch to add parent relation via VSTS client API

I am trying to programmatically add a parent-child relationship between two work items. I am using the Microsoft Team Foundation and Visual Studio Services libraries to export and import TFS 2015 and VSTS backlog objects.…
Ross
  • 163
  • 2
  • 9
6
votes
1 answer

kubernetes strategic merge patch

Hi I am following this doc https://github.com/kubernetes/kubernetes/blob/master/docs/devel/api-conventions.md#strategic-merge-patch for strategic-merge-patch to partially update the JSON objects using PATCH REST API. The document says that it can…
priyank
  • 857
  • 2
  • 18
  • 35
6
votes
1 answer

Using .Net Core Web API with JsonPatchDocument

I am using JsonPatchDocument to update my entities, this works well if the JSON looks like the following [ { "op": "replace", "path": "/leadStatus", "value": "2" }, ] When i create the object it converts it with the Operations node var patchDoc =…
R4nc1d
  • 2,923
  • 3
  • 24
  • 44
6
votes
3 answers

How is the tilde escaping in the JSON Patch RFC supposed to operate?

Referencing https://www.rfc-editor.org/rfc/rfc6902#appendix-A.14: A.14. ~ Escape Ordering An example target JSON document: { "/": 9, "~1": 10 } A JSON Patch document: [ {"op": "test", "path": "/~01", "value": 10} ] The resulting…
OmnipotentEntity
  • 16,531
  • 6
  • 62
  • 96
5
votes
4 answers

FluentValidator and JsonPatchDocument

I have WebAPI (.NET Core) and use FluentValidator to validate model, including updating. I use PATCH verb and have the following method: public IActionResult Update(int id, [FromBody] JsonPatchDocument jsonPatchDocument) …
Oleg Sh
  • 8,496
  • 17
  • 89
  • 159
5
votes
1 answer

How to implement a RESTful API for order changes on large collection entries?

I have an endpoint that may contain a large number of resources. They are returned in a paginated list. Each resource has a unique id, a rank field and some other data. Semantically the resources are ordered with respect to their rank. Users…
Hakan Baba
  • 1,897
  • 4
  • 21
  • 37
5
votes
0 answers

Validate Values before Apply PATCH in REST

I'm looking for a way to validate and check the values of the model that is sent to my PATCH method for updating. I haven't found my answer yet. I've read the JsonPatch Documentation but I didn't find what I want. Scenario: I have a RESTful Web API,…
Arad Alvand
  • 8,607
  • 10
  • 51
  • 71
5
votes
1 answer

Patching an object with an array of objects

I have a many-to-many relationship between Courses and Students for a school. Here's is what I have for a Course: public class Course { public Guid CourseId { get; set; } public string Name { get; set; } public…
Steven
  • 18,761
  • 70
  • 194
  • 296
1
2
3
12 13