The way I read the the paragraph you sent, I would say.. no you are not able to do this. My understanding is that RFC 7396 is intended as a very simple no-fuss patch format.

If you want something with more features, consider using RFC 6902 instead.

Answer from Evert on Stack Overflow
🌐
RFC Editor
rfc-editor.org › rfc › rfc7396.html
RFC 7396: JSON Merge Patch
RFC 7396 JSON Merge Patch October 2014 A user agent wishing to change the value of the "title" member from "Goodbye!" to the value "Hello!", add a new "phoneNumber" member, remove the "familyName" member from the "author" object, and replace the "tags" array so that it doesn't include the word "sample" would send the following request: PATCH /my/resource HTTP/1.1 Host: example.org Content-Type: application/merge-patch+json { "title": "Hello!", "phoneNumber": "+01-123-456-7890", "author": { "familyName": null }, "tags": [ "example" ] } The resulting JSON document would be: { "title": "Hello!", "author" : { "givenName" : "John" }, "tags": [ "example" ], "content": "This will be unchanged", "phoneNumber": "+01-123-456-7890" } 4.
Top answer
1 of 2
1

The way I read the the paragraph you sent, I would say.. no you are not able to do this. My understanding is that RFC 7396 is intended as a very simple no-fuss patch format.

If you want something with more features, consider using RFC 6902 instead.

2 of 2
0

Summary

You can achieve what you want with RFC 7396.

The spec is a bit vague.

But their example shows exactly what you want.

RFC 7396 Example

Given the following example JSON document:

   {
     "title": "Goodbye!",
     "author" : {
       "givenName" : "John",
       "familyName" : "Doe"
     },
     "tags":[ "example", "sample" ],
     "content": "This will be unchanged"
   }

PATCH /my/resource HTTP/1.1
Host: example.org
Content-Type: application/merge-patch+json

   {
     "title": "Hello!",
     "phoneNumber": "+01-123-456-7890",
     "author": {
       "familyName": null
     },
     "tags": [ "example" ]
   }

The resulting JSON document would be:

   {
     "title": "Hello!",
     "author" : {
       "givenName" : "John"
     },
     "tags": [ "example" ],
     "content": "This will be unchanged",
     "phoneNumber": "+01-123-456-7890"
   }

Conclusions

As you can see, the nested object author has been updated by deleting attribute familyName, but it retained attribute givenName even though that was not included in the patch document.

For me that clearly shows that you do not need to provide nested attributes or objects that you do not want to change and they should be retained.

Consequently, if you want to delete them, you need to include them with null value.

Note that the authors of spec managed to get most of the possible changes into one example (well done):

  • change value of existing attribute title
  • change object author
  • delete nested attribute familyName
  • keep unchanged nested attribute givenName
  • change array value of tags
  • keep unchanged attribute content
  • add attribute phoneNumber
🌐
RFC Editor
rfc-editor.org › rfc › rfc7396.txt
Internet Engineering Task Force (IETF) P. Hoffman
Internet Engineering Task Force (IETF) P. Hoffman Request for Comments: 7396 VPN Consortium Obsoletes: 7386 J.
🌐
IETF
datatracker.ietf.org › doc › html › rfc7396
RFC 7396 - JSON Merge Patch
RFC 7396 JSON Merge Patch October 2014 A user agent wishing to change the value of the "title" member from "Goodbye!" to the value "Hello!", add a new "phoneNumber" member, remove the "familyName" member from the "author" object, and replace the "tags" array so that it doesn't include the word "sample" would send the following request: PATCH /my/resource HTTP/1.1 Host: example.org Content-Type: application/merge-patch+json { "title": "Hello!", "phoneNumber": "+01-123-456-7890", "author": { "familyName": null }, "tags": [ "example" ] } The resulting JSON document would be: { "title": "Hello!", "author" : { "givenName" : "John" }, "tags": [ "example" ], "content": "This will be unchanged", "phoneNumber": "+01-123-456-7890" } 4.
🌐
RFC Editor
rfc-editor.org › info › rfc7396
Information on RFC 7396 » RFC Editor
Other actions: Submit Errata | Find IPR Disclosures from the IETF | View History of RFC 7396 · This specification defines the JSON merge patch format and processing rules. The merge patch format is primarily intended for use with the HTTP PATCH method as a means of describing a set of ...
🌐
ACM Digital Library
dl.acm.org › doi › abs › 10.17487 › RFC7396
RFC 7396: JSON Merge Patch | Guide books
This specification defines the JSON merge patch format and processing rules. The merge patch format is primarily intended for use with the HTTP PATCH method as a means of describing a set of modifi...
🌐
GitHub
github.com › nlohmann › json › pull › 4965
support JSON Merge Patch (RFC 7396) diff creation by satelliteprogrammer · Pull Request #4965 · nlohmann/json
However, and in contrast to JSON Patch (RFC 6902), a JSON Merge Patch cannot express certain modifications, e.g., changing an array element at a specific index, or setting a specific object value to null. The null value in a JSON Merge Patch is used to remove the key from the object. The diff algorithm is not part of the RFC 7396, but it was tested against all examples provided, plus additional cases on how null values are handled.
Author   nlohmann
🌐
Daniel Gustaw
gustawdaniel.com › posts › en › json-merge-patch
Daniel Gustaw - Rust implementation of RFC 7396 - JSON Merge Patch
JSON Merge Patch is a standardized algorithm for describing changes to a JSON document by treating it as a collection of unordered key-value pairs. Defined in RFC 7396, JSON Merge Patch provides a simple and efficient way to update JSON documents ...
Find elsewhere
🌐
Hacker News
news.ycombinator.com › item
RFC 7396 – JSON Merge Patch | Hacker News
July 8, 2018 - JSON Patch can be MVCC ops to apply to an object, where as a JSON Merge Patch is overrides · I don't see how that's better. I'm legitimately asking as I've implemented JSON Patch support in API gateways due to the "over-engineered" & useful applications in real life
🌐
JSONViewerTool
jsonviewertool.com › home › json merge patch
JSON Merge Patch (RFC 7396) | Apply Merge Patch
The JSON Merge Patch tool applies RFC 7396 merge patches to update JSON documents using a simple, declarative format. Unlike JSON Patch (RFC 6902), which uses a list of operations, JSON Merge Patch uses a partial JSON object to describe changes.
🌐
GitHub
github.com › moejoe › Moejoe.AspNet.JsonMergePatch
GitHub - moejoe/Moejoe.AspNet.JsonMergePatch: A RFC 7396 JsonMergePatch Implementation for .NET
A RFC 7396 JsonMergePatch Implementation for .NET. Contribute to moejoe/Moejoe.AspNet.JsonMergePatch development by creating an account on GitHub.
Author   moejoe
🌐
Stéphane Bortzmeyer
bortzmeyer.org › 7396.pdf pdf
RFC 7396 : JSON Merge Patch St´ephane Bortzmeyer <stephane+blog@bortzmeyer.org>
RFC 7396 : JSON Merge Patch · St´ephane Bortzmeyer · <stephane+blog@bortzmeyer.org> Premi`ere r´edaction de cet article le 1 novembre 2014 · Date de publication du RFC : Octobre 2014 · https://www.bortzmeyer.org/7396.html · —————————- La commande HTTP PATCH permet ...
🌐
GitHub
github.com › QuentinRoy › tiny-merge-patch
GitHub - QuentinRoy/tiny-merge-patch: An FP-ready implementation of the JSON Merge Patch RFC 7396
An implementation of the JSON Merge Patch RFC 7396: a standard format used to describe modifications to JSON documents.
Author   QuentinRoy
🌐
GitHub
github.com › clue › php-json-merge-patch
GitHub - clue/php-json-merge-patch: JSON merge patch (RFC 7396) is a simple alternative to JSON patch (RFC 6902) – dead-simple PHP library
JSON merge patch (RFC 7396) is a simple alternative to JSON patch (RFC 6902) – dead-simple PHP library - clue/php-json-merge-patch
Starred by 7 users
Forked by 2 users
Languages   PHP
🌐
Database Guide
database.guide › json_merge_patch-perform-an-rfc-7396-compliant-merge-of-json-documents-in-mysql
JSON_MERGE_PATCH() – Perform an RFC 7396 Compliant Merge of JSON Documents in MySQL
July 21, 2018 - In MySQL, the JSON_MERGE_PATCH() function performs an RFC 7396 compliant merge of two or more JSON documents, without preserving members having duplicate keys.
🌐
Stack Overflow
stackoverflow.com › questions › 49754484 › bulk-update-using-the-json-merge-patch-specification-rfc-7396
rest - Bulk update using the JSON Merge Patch Specification (RFC 7396) - Stack Overflow
I am having a problem understanding how to use JSON Merge Patch (RFC 7396) when dealing with bulk updates, or if it even makes sense. I can't find any specifications or examples. Description We hav...
🌐
GitHub
github.com › idubrov › json-patch
GitHub - idubrov/json-patch: RFC 6902 (JSON Patch) / RFC 7396 (JSON Merge Patch) implementation for Rust
A JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7396) implementation for Rust.
Starred by 167 users
Forked by 24 users
Languages   Rust 99.9% | Shell 0.1% | Rust 99.9% | Shell 0.1%