How to iterate JSON body for x times and pass variables from Array List

Hello,

I would like to dynamically create entire child elements of a JSON and pass Array list variable from the previous object…

My JSON looks like,

.exec(
http(“POST_Method”)
.post(localhost+"/test")

.body(StringBody("""{
“parentId” : “ABCD123”
{

“childDetails”:[
“globalUtilizedAmount”:{ //child element 1
“currency”:“USD”,
“amount”: +arr.get(0)+ //array variable 0
},
“globalOriginalAmount”:{ //child element 2
“currency”:“USD”,
“amount”: +arr.get(1)+ //array variable 1
}

]
}
}""")).asJson

.headers(ApiHeaders)
)

From the above JSON i would like generate,

  1. multiple globalUtilizedAmount using loop - (here I’ve shown 2 elements as part of childDetails)
  2. replace amount object’s value with an array list variable which ive generated from previous object.

Kindly help!

Try using jsonStringify Gatling EL function.

https://gatling.io/docs/current/session/expression_el/