Crate sjdiff

Source
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§

Diff
Use DiffBuilder to build Diff first and run Diff::compare to get the difference between two JSON values.
DiffBuilder
Builder for Diff.
IgnorePath
IgnorePathBuilder
Builder for IgnorePath.
Map
Path

Enums§

ArrayDifference
ArrayIndex
DiffBuilderError
Error type for DiffBuilder
Difference
EntryDifference
IgnorePathBuilderError
Error type for IgnorePathBuilder
IgnorePathCondition
PathElement
ScalarDifference
Type