Expand description
§Structural JSON Diff Library for Rust
sjdiff
– is a library for Rust that compares two JSON values and produces a structural difference between them.
§Examples
Compare two objects
fn main() {
let obj1 = serde_json::json!({
"user": "John",
"age": 31
});
let obj2 = serde_json::json!({
"user": "John",
"age": 33
});
let diff = sjdiff::DiffBuilder::default()
.source(obj1)
.target(obj2)
.build()
.unwrap();
let diff = diff.compare();
serde_json::to_writer_pretty(std::io::stdout(), &diff).unwrap();
}
Output:
{
"difference_of": "object",
"different_entries": {
"age": {
"entry_difference": "value",
"value_diff": {
"difference_of": "scalar",
"source": 31,
"target": 33
}
}
}
}
Structs§
- Use
DiffBuilder
to buildDiff
first and runDiff::compare
to get the difference between two JSON values. - Builder for
Diff
. - Builder for
IgnorePath
.
Enums§
- Error type for DiffBuilder
- Error type for IgnorePathBuilder