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