ignore_with_rhai_script/ignore_with_rhai_script.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
fn main() {
let obj1 = serde_json::json!({
"users": [
{
"name": "Joe",
"age": 43,
},
{
"name": "Ana",
"age": 33,
"animals": {
"type": "dog"
}
},
]
});
let obj2 = serde_json::json!({
"users": [
{
"name": "Joe",
"age": 43,
},
{
"name": "Ana",
"age": 33,
"animals": {
"type": "cat"
}
},
]
});
let script = r#"
let res = target.value_by_path("users.[_].age", curr_path);
res == 33
"#;
let diff = sjdiff::DiffBuilder::default()
.source(obj1)
.target(obj2)
.ignore_path_with_condition("users.[_].animals.type", sjdiff::IgnorePathCondition::Rhai(script.to_string()))
.build();
let diff = diff.unwrap().compare();
print!("{:?}", diff);
}