#json-diff #json #serde-json #diff #serde #json-path

bin+lib sjdiff

Structural JSON Diff Library for Rust

3 releases

0.0.7 Dec 3, 2024
0.0.6 Dec 1, 2024
0.0.5 Nov 23, 2024

#488 in Encoding

Download history 107/week @ 2024-11-18 99/week @ 2024-11-25 264/week @ 2024-12-02 31/week @ 2024-12-09

501 downloads per month

MIT license

41KB
932 lines

Structural JSON Diff Library for Rust

sjdiff – is a library for Rust that compares two JSON values and produces a structural difference between them.

Features

  • Compare any JSON value.
  • Ignore JSON paths so they are not included in the result diff.
  • Customize the equation logic, e.g. null == [], 0.111 == 0.11, 2023-07-25T15:30:01Z == 2023-07-25T15:30:00Z.

Example

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();
}

See more in the examples.

Credits

Thanks to teajey – author of serde_json_diff. I forked that project and implemented additional features that were essential for my workflow.

License

MIT

Dependencies

~8MB
~141K SLoC