Function json_patch::patch_unsafe
source · pub fn patch_unsafe(
doc: &mut Value,
patch: &[PatchOperation],
) -> Result<(), PatchError>
Expand description
Patch provided JSON document (given as serde_json::Value
) in-place. Different from patch
if any patch failed, the document is left in an inconsistent state. In case of internal error
resulting in panic, document might be left in inconsistent state.
§Example
Create and patch document:
#[macro_use]
use json_patch::{Patch, patch_unsafe};
use serde_json::{from_value, json};
let mut doc = json!([
{ "name": "Andrew" },
{ "name": "Maxim" }
]);
let p: Patch = from_value(json!([
{ "op": "test", "path": "/0/name", "value": "Andrew" },
{ "op": "add", "path": "/0/happy", "value": true }
])).unwrap();
patch_unsafe(&mut doc, &p).unwrap();
assert_eq!(doc, json!([
{ "name": "Andrew", "happy": true },
{ "name": "Maxim" }
]));