Showing results for 
Search instead for 
Did you mean: 

Capture an Entire JSON response to a property?

Community Hero

Capture an Entire JSON response to a property?



I feel a bit dumb asking this question cos I feel like I should know the answer.


Anyway - I have a POST request that generates a .json response.


I would like to capture the whole request's response into a single property.


Does anyone know how to do this?


example of the .json is as follows:


"@odata.context": "$metadata#phonecalls",
"value": [
"@odata.etag": "W/\"3844463\"",
"_owningbusinessunit_value": "a6ae8ca6-7ae3-e711-8118-5065f38bc491",
"statuscode": 127130002,
"activityid": "2266985a-013f-e811-8122-5065f38be511",
"actualdurationminutes": 30,
"activityadditionalparams": null,
}, {
"@odata.etag": "W/\"3844464\"",
"_owningbusinessunit_value": "a6ae8ca6-7ae3-e711-8118-5065f38bc491",
"statuscode": 127130002,
"activityid": "ee104a67-013f-e811-8122-5065f38be511",
"actualdurationminutes": 30,
"activityadditionalparams": null,
}, {
"@odata.etag": "W/\"3844465\"",
"_owningbusinessunit_value": "a6ae8ca6-7ae3-e711-8118-5065f38bc491",
"statuscode": 127130002,
"activityid": "466c0c74-013f-e811-8122-5065f38be511",
"actualdurationminutes": 30,
"activityadditionalparams": null,

I think I could do this in XML because you just take the root tag in the transfer I'm guessing - but I can't seem to do that when the response is .json.  I was playing around using an XMLDatasource with the source property option of 'ResponseAsXML', but I was unsuccessful and am unsure if this will achieve what I want.


Again - thanks to all for any helpful hints/tips/guidance,



if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Community Hero

Re: Capture an Entire JSON response to a property?

Hi Richie,


Well you don't have to save the whole json response in a property because ReadyApi already does that automatically for you. Smiley Very Happy


For instance, I have a request which returns the following raw response:


HTTP/1.1 200 OK
Content-Type: application/json
Server: Jetty(6.1.26)

{ "key" : "value" }

When the request is finished the JSON is automatically saved as:




You can later reference this by using the usual SoapUI syntax: ${NameOfYourTestCase#Response}

If my answer helped please click on the 'Accept as Solution' button.

Re: Capture an Entire JSON response to a property?

You can get an entire JSON response in an assertion script step.


import groovy.json.JsonSlurper
def resp = messageExchange.response.responseContent
def jsonSlurper = new JsonSlurper().parseText(resp)


from there you can access fields like jsonSlurper.fieldName1


or output the json jsonSlurper.toString()


I know you really want to do this in an ordinary Groovy script though.


I have a real working test case structured with the following steps

Test case xyz

   groovy script 1

  properties (2)

  request step 1

  groovy script 2

  request step 2


So in my groovy script 2 I have code like


import static groovy.json.JsonOutput.toJson;
import groovy.json.JsonSlurper
import groovy.json.JsonBuilder

def previousTestStep = testRunner.getTestCase().getTestStepByName("request step 1")
String propertySpec = '${' + + '#Response}'
def response = context.expand(propertySpec)
def jsonSlurper = new JsonSlurper().parseText(response)

I probably don't use the first import in the code above. 


I use JsonBuilder to construct new json and then set the json for the request step 2.


You can print out the json from the response (I assume response to your POST) jsonSlurper.toString()


The catch is that you nave to know the name of the request test step.



New Here?
Join us and watch the welcome video:
Top Kudoed Authors