Forum Discussion
nmrao
11 years agoCommunity Hero
Not very good at Json path.
But below script assertion should do the job[using the assumed json array]
import net.sf.json.groovy.JsonSlurper
def jsonText = '''{ "cars": [ { "name" : "Jetta", "madeBy" : "Volkswagen" }, { "name" : "Polo GT", "madeBy" : "Volkswagen" }, { "name" : "i30", "madeBy" : "Hyundai" } ] }''' def jsonSlurper = new JsonSlurper() def cars = jsonSlurper.parseText(jsonText).cars def expectedName = 'Jetta' // You may use test case propperty here if you wish def expectedValueExists=false if (cars) { cars.each{if (it.name==expectedName) {expectedValueExists=true} } } if (expectedValueExists) { log.info "Expected car ${expectedName} exists"} assert expectedValueExists, "Expected car name does not exists"
Hope this is helpful