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

Adding an item to a Dictionary using JsonPatch in ASP.NET Core

I have the following environment and version of .NET Core .NET SDK (reflecting any global.json): Version: 5.0.100 Commit: 5044b93829 Runtime Environment: OS Name: Mac OS X OS Version: 11.0 OS Platform: Darwin RID: …
marcus
  • 9,616
  • 9
  • 58
  • 108
2
votes
0 answers

Using Jackson annotations with JsonPatch

If I have the following dto in spring boot public class PersonDto { @JsonProperty(access = Access.READ_ONLY) private Long id; @NotBlank private String name; //@NotNull @JsonProperty(access = Access.READ_ONLY) private Integer age; } And I…
David de Castro
  • 151
  • 1
  • 5
2
votes
1 answer

Using JSON Merge Patch, how do I reference members of sub-collection?

Using the JSON Merge Patch specification, is there a way to identify members of a sub-collection in the target - for modification or deletion? With the twist, that key may be flagged as readOnly! For example, given the following original JSON…
Nicholas Pappas
  • 10,439
  • 12
  • 54
  • 87
2
votes
1 answer

how to do a JSON diff/patch between 2 big nested json from .net backend to js frontend?

i have a very big json that has a very small changes each second. im using asp.net core 3.1 and signalr core. and clients are using browsers running pure js and jquery. right now for every change im re sending all the json again. i know that its not…
Mrjm
  • 121
  • 2
  • 10
2
votes
2 answers

javax.json.JsonPatch unsupported as @RequestBody in Spring Webflux Microservice

I'm currently messing around with a Spring Webflux microservice and trying to implement an @PatchMapping which consumes an JsonPatch object as @RequestBody like so: @PatchMapping("/{id}", consumes = ["application/json-patch+json"]) fun updateFriend(…
Antonio Dell
  • 497
  • 5
  • 17
2
votes
2 answers

Jackson deserialise JsonPatch with object value

I'mu using JsonPatch (JSR-374) with implementation from Apache org.apache.johnzon:johnzon-core:1.2.4 in my Spring project PATCH endpoint: @Bean @Primary public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) { ObjectMapper…
Tomáš Mika
  • 210
  • 1
  • 13
2
votes
1 answer

JsonPatchDocument throwing a 400 error when calling API

I'm getting a "Response status code does not indicate success: 400 (Bad Request)." error when making a HTTP PATCH call on my API. It works when I remove the "[FromBody] JsonPatchDocument param" from my API method. Any ideas why? It's a asp.net core…
inliner49er
  • 1,300
  • 1
  • 11
  • 19
2
votes
1 answer

ember-data and json-patch requests

Can ember-data send json-patch PATCH on model.save() call? (with media type application/json-patch+json RFC6902) The documentation says yes but with no…
Slim
  • 1,256
  • 1
  • 13
  • 25
2
votes
2 answers

How to increment value with JSON Patch?

We need to update a counter through our REST API and we're using JSON Patch for our PATCH calls, so it should be something like this: {"op":"increment", "path":"/counter", "value": 1 } The problem is JSON Patch doesn't support this type of…
2
votes
1 answer

Is there a way to disable automatic JSON PATCH application in Wildfly

when using HTTP-PATCH Resources in JAX-RS on Wildfly (tested with 14 and 18), some automagic happens that calls the same resource path using GET, applies the changes from the JSON-PATCH and calls the actual method with the result. $ curl…
Max Fichtelmann
  • 3,366
  • 1
  • 22
  • 27
2
votes
1 answer

How do I use IObjectAdapter with JsonPatch?

I'm trying to prevent certain properties of a DTO from being patched when calling patch.ApplyTo(object, adapter). My current plan is to put a custom attribute onto properties that are to be ignored, and, using that adapter, only allow operations to…
idlackage
  • 2,715
  • 8
  • 31
  • 52
2
votes
0 answers

Reuse JSON patches in kustomize

I am using a JSON patch in my overlay kustomization file in order to set the image to use for my pods. The patch itself is pretty generic: - op: replace path: /spec/template/spec/containers/0/image value: myRegistry/myImage:myTag And in my…
ITChap
  • 4,057
  • 1
  • 21
  • 46
2
votes
0 answers

Is there a constant for application/json-patch+json already defined in ASP.Net Core?

I am looking the following Content-Type in ASP.Net Core that is used when patching an entity: application/json-patch+json There is the class MediaTypeNames as answered in this SO question but it does not have the patch option.
Kzryzstof
  • 7,688
  • 10
  • 61
  • 108
2
votes
0 answers

Is updating an object nested inside an array via JsonPatchDocument possible?

I'm using Microsoft.AspNetCore.JsonPatch V2.1.1. I have an object structure like this: { "key" : "value", "nested" : [ { "key" : "value" } ] } Now I want to update the key in the nested object within the array: [ {"op" : "replace",…
Pascal
  • 125
  • 1
  • 15
2
votes
0 answers

Error on JsonPatch Add on Array

I'm using KevinDockx-Jsonpatch library (v2.1.0 - GitHub) in a .NET Web API project to receive jsonpatch partial updates from a Web API. I'm trying to add an element to an array with a patch like this: [{ "op": "add", "path": "/links/8", "value": { …
D. Pesc.
  • 196
  • 15