Function json_patch::from_value

source ·
pub fn from_value(value: Value) -> Result<Patch, Error>
Expand description

Create JSON Patch from JSON Value

Examples

Create patch from serde_json::Value:

#[macro_use]
extern crate serde_json;
extern crate json_patch;

use json_patch::{Patch, from_value};

let patch_value = json!([
  { "op": "test", "path": "/0/name", "value": "Andrew" },
  { "op": "add", "path": "/0/happy", "value": true }
]);
let patch: Patch = from_value(patch_value).unwrap();

Create patch from string:

#[macro_use]
extern crate serde_json;
extern crate json_patch;

use json_patch::Patch;
use serde_json::from_str;

let patch_str = r#"[
  { "op": "test", "path": "/0/name", "value": "Andrew" },
  { "op": "add", "path": "/0/happy", "value": true }
]"#;
let patch: Patch = from_str(patch_str).unwrap();