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

**URL:** <https://community.gatling.io/t/how-to-iterate-json-body-for-x-times-and-pass-variables-from-array-list/5790>\
**Category:** Gatling (Open-Source)\
**Created:** [September 7, 2020, 3:15pm UTC](https://community.gatling.io/t/how-to-iterate-json-body-for-x-times-and-pass-variables-from-array-list/5790 "2020-09-07T15:15:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bala\_kumar](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@Bala\_kumar](https://community.gatling.io/u/Bala_kumar)\
**Post date:** [September 7, 2020, 3:15pm UTC](https://community.gatling.io/t/how-to-iterate-json-body-for-x-times-and-pass-variables-from-array-list/5790/1 "2020-09-07T15:15:10Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [September 7, 2020, 3:26pm UTC](https://community.gatling.io/t/how-to-iterate-json-body-for-x-times-and-pass-variables-from-array-list/5790/2 "2020-09-07T15:26:34Z")

</div>

Try using jsonStringify Gatling EL function.

[https://gatling.io/docs/current/session/expression\_el/](https://gatling.io/docs/current/session/expression_el/)
