Forum Discussion
pb1
6 years agoContributor
I'd use the following function to validate json
import groovy.json.JsonSlurper
Boolean isValidJson(jsonString){
result = true
try{
new JsonSlurper().parseText(jsonString)
}
catch(Exception e){
result = false
}
return result
}And then call the validation before passing the values to assertEquals:
assert isValidJson(response) == true assert isValidJson(step_response) == true JSONAssert.assertEquals(step_response,response,false)
Instead of asserting it to true, you can also just use an if() to handle the malformatted json as you see fit.