How to extract the parameter from Json Response Using Groovy?

ChanGan picture ChanGan · May 16, 2013 · Viewed 24.5k times · Source

The below is my response..

{"activation":{"existing":false, "customer": new}}

Now when I use

testRunner.testCase.getTestStepByName("xxx").getPropertyValue("response")

The above script is extracting the response. Now I wanted to extract "customer" value.

How to do this?

Thanks

Answer

ChanGan picture ChanGan · May 16, 2013
import groovy.json.JsonSlurper

responseContent = testRunner.testCase.getTestStepByName("xxx").getPropertyValue("response")
slurperresponse = new JsonSlurper().parseText(responseContent)
log.info (slurperresponse.activation.customer)