2 releases
0.1.1 | Oct 29, 2021 |
---|---|
0.1.0 | Oct 29, 2021 |
#1554 in Encoding
37KB
939 lines
Jatch
A Json Patching library in Rust, as per RFC6902
Easily find the difference between 2 JSONs:
let before = json!({"a": 123});
let after = json!({"a": 123, "b": "hello"});
let patches = diff(before, after);
assert_eq!(patches, vec![Patch::Add {
value: json!("hello"),
path: Path::new("/b"),
}]);
lib.rs
:
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"),
}
);
Dependencies
~0.7–1.6MB
~34K SLoC