Function json_patch::merge
source · Expand description
Patch provided JSON document (given as serde_json::Value
) in place with JSON Merge Patch
(RFC 7396).
Example
Create and patch document:
#[macro_use]
extern crate serde_json;
extern crate json_patch;
use json_patch::merge;
let mut doc = json!({
"title": "Goodbye!",
"author" : {
"givenName" : "John",
"familyName" : "Doe"
},
"tags":[ "example", "sample" ],
"content": "This will be unchanged"
});
let patch = json!({
"title": "Hello!",
"phoneNumber": "+01-123-456-7890",
"author": {
"familyName": null
},
"tags": [ "example" ]
});
merge(&mut doc, &patch);
assert_eq!(doc, json!({
"title": "Hello!",
"author" : {
"givenName" : "John"
},
"tags": [ "example" ],
"content": "This will be unchanged",
"phoneNumber": "+01-123-456-7890"
}));