I am comparing JSON responses from two different servers. They should basically match but due to caching, there are some small differences in fields such a temperature, wind speed, etc.
I am currently using a customization to ignore certain fields that always fail like this:
JSONAssert.assertEquals(response2.getResponseBodyContent(), response1.getResponseBodyContent(),
new CustomComparator(JSONCompareMode.LENIENT,
new Customization("**.TimeStamp", {a, b -> true}),
new Customization("**.EpochTime", {a, b -> true})
));
Questions:
- How would I go about specifying a range (temperature can be within 10)?
- How to specify that the value only matches a certain type (string, integer)?
JSON Samples:
JSON 1
"Temperature":{
"Metric":{
"Value":4.6,
"Unit":"C"
},
"Imperial":{
"Value":40.0,
"Unit":"F"
}
},
"Wind":{
"Direction":{
"Degrees":293,
"English":"WNW"
},
"Speed":{
"Metric":{
"Value":19.4,
"Unit":"km/h"
},
"Imperial":{
"Value":12.1,
"Unit":"mi/h"
}
}
JSON 2
"Temperature":{
"Metric":{
"Value":5.1,
"Unit":"C"
},
"Imperial":{
"Value":43.0,
"Unit":"F"
}
},
"Wind":{
"Direction":{
"Degrees":271,
"English":"ENE"
},
"Speed":{
"Metric":{
"Value":19.9,
"Unit":"km/h"
},
"Imperial":{
"Value":12.4,
"Unit":"mi/h"
}
}
I am using a testing tool called Katalon which supports groovy/java. Any help would be greatly appreciated. Thanks!