Crate jatch

Source
Expand description

A crate to provide a fast, correct and safe implementation of JSON Patch (RFC 6902)

It can apply patches to JSON documents:

let doc = json!({"hello": "world"});
let patch = Patch::Add {
    path: Path::new("/foo"),
    value: json!("bar"),
};
assert_eq!(
    apply(doc, vec![patch]).unwrap(), 
    json!({
        "hello": "world",
        "foo": "bar",
    })
);

It can also calculate the diffs between 2 JSONs:

let patches = diff(
  json!({"hello": "world"}),  
  json!({"hello": "world", "foo": "bar"}),
);
assert_eq!(
    patches[0], 
    Patch::Add {
      path: Path::new("/foo"),
      value: json!("bar"),
    }
);

Structs§

Path
A reference to location in a JSON document, as defined in RFC 6901

Enums§

Error
An error encountered while performing JSON Patch operations
Patch
A Json Patch operation

Functions§

apply
Applies a collection of JSON Patches to a JSON document The patches are applied in order, and if any individual patch fails, the whole function fails
apply_single
Applies a single JSON Patch to a JSON document
diff
Compute the diff between two JSON Documents