Reputation: 649
I have a JSON file that has same fields with different values. Now I have to write a groovy script that compares the two files which will ignore fields value.
e.g
json1 = '{"name" : "abc", "value": "123", "field" : "xyz"}'
json2 = '{"name" : "efg", "value": "567", "field" : "xyz"}'
assert should return true
json1 = '{"value": "123", "field" : "xyz"}'
json2 = '{"name" : "efg", "value": "567", "field" : "xyz"}'
assert should return false
I have try with the following code (from here) and always return false for both case
def slurp1 = new JsonSlurper().parseText(json1)
def slurp2 = new JsonSlurper().parseText(json2)
assert slurp1 == slurp2
Upvotes: 1
Views: 701