Forum Discussion
pb1
5 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.
Related Content
- 3 years agogroovyguy
- 5 years agokaiiii
- 2 years agojaredjamieson