andreyvit / json-diff

Structural diff for JSON files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Custom Compare Rule

lihuacai168 opened this issue · comments

Source Data

baseJson: [{
  "a": 100,
  "b": 100
}]

actualJson:
[{
  "a": 101,
  "b": 105
}]

Custom Rule

threshold = 0.01
diff = abs((actualJsonValue - baseJsonValue)/baseJsonValue)
if diff > threshold; then regard as diff;
else, it regard as no diff

In this case
abs((101-100) / 100) > 0.01 is false, so key a is  no diff
abs((105-100) / 100) > 0.01 is ture, so key b is diff