Saving and reusing JSON response

I get json response something like the following:

`
“response”:{“numFound”:1,“start”:0,“docs”:[
{“sg_cust_type”:“3”,“sg_crd_indvl_id”:“999999”,
“sg_crd_org_id”:“888888”,“sg_uaf_ind”:“N”,“sg_full_name”:[“Test LAST_NM”],
“sg_nm_address”:[“ADD1 |C/o |Street |STE |CITY STATE_CD zip | “,
“ADD2 |C/o |Street |STE |CITY STATE_CD zip”,
“ADD3 |C/o |Street |STE |CITY STATE_CD zip”,
“ADD4 |C/o |Street |STE |CITY STATE_CD zip”],
“sg_smr_cust_id”:“789456”,“sg_custid_id”:“123456”,“sg_nm_last_name”:[“LAST_NM”],“id”:“22026556”,“sg_id_list_ind”:“Y”,
“sg_nm_state”:[“MD”],“sg_nm_zip”:[“20850”],“sg_nm_type”:[“1”],“sg_cust_id”:””,
“sg_nm_first_name”:[“Test”],“version”:1481868714324262915}]}

`

How can I parse this entire json in key value pair, so, I can reuse it again in the same request(another Ajax call).

I found some json stuff on Checks page but since I am not using as a check but as a way to populate another request I am not sure if thats the right way to do it.

Thanks,
Abhi

Ok the following works and gets me bodyString but how do I access this variable

.check(bodyString.saveAs(“jsonBody”))

println “${jsonBody}” prints {jsonBody}

To answer your question, you will need to be a little more specific about the follow-on request. Can you post a more complete code sample, even if it is only conceptual?

Here is my code: (work in progress, of course)

val scn = scenario("SGSimulation") .exec(http("Snapshot") .get("""/snapshot?id=20011461&ns=U01JVEggSk9ILE4&cs=35622353""") .resources(http("request_1") .get(uri1 + """/data/customerInfo?customerId=20011461&listId=0&wt=json""")// Json output needs to massaged and passed on to another ajax call below //.check(jsonPath("$.response.docs").findAll.saveAs("pList")) .check(bodyString.saveAs("jsonBody")) http("request_30") .get(uri2 + """?&callback=angular.callbacks._4&facetType=json&q=firm:{JSON_OUTPUT""")// This is one the places I will passing the json output. ))

I am very new gatling. Will appreciate your help.

Abhinav

In the URI of an http() request, you can use EL to add values stored in the session. Same thing with headers and request body.

Just extract the part you need in the .check of the request that is providing it to you, store it in appropriate session variables, and then embed those variables in future requests.

Exactly how you do the “massaging” depends on what kind of massaging you need to do. But you can always insert an .exec( session => … ) statement in between to do the massaging programmatically.

Ok. Will try it. Thanks a lot!