philiprehberger-json-diff 0.1.2

Structural JSON diff with path tracking for Rust
Documentation

rs-json-diff

CI Crates.io License

Structural JSON diff with path tracking for Rust.

Installation

Add to your Cargo.toml:

philiprehberger-json-diff = "0.1"

Usage

use philiprehberger_json_diff::{diff, diff_summary};
use serde_json::json;

let a = json!({
    "name": "Alice",
    "age": 30,
    "tags": ["rust", "dev"]
});

let b = json!({
    "name": "Alice",
    "age": 31,
    "tags": ["rust", "senior"],
    "active": true
});

let changes = diff(&a, &b);
for change in &changes {
    println!("{}", change);
}

let summary = diff_summary(&changes);
println!("Added: {}, Removed: {}, Modified: {}", summary.added, summary.removed, summary.modified);

API

Item Description
diff(a: &Value, b: &Value) -> Vec<Change> Compute structural diff between two JSON values
diff_summary(changes: &[Change]) -> DiffSummary Summarize a list of changes by type counts
ChangeType Enum: Added, Removed, Modified
Change Struct with path, change_type, old_value, new_value
DiffSummary Struct with added, removed, modified counts

License

MIT