# how to dynamically fill JSON array with object

**URL:** <https://community.gatling.io/t/how-to-dynamically-fill-json-array-with-object/5774>\
**Category:** Gatling (Open-Source)\
**Created:** [August 24, 2020, 11:01am UTC](https://community.gatling.io/t/how-to-dynamically-fill-json-array-with-object/5774 "2020-08-24T11:01:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghazouani\_nada](https://avatars.discourse-cdn.com/v4/letter/g/c37758/32.png) [@ghazouani\_nada](https://community.gatling.io/u/ghazouani_nada)\
**Post date:** [August 24, 2020, 11:01am UTC](https://community.gatling.io/t/how-to-dynamically-fill-json-array-with-object/5774/1 "2020-08-24T11:01:17Z")

</div>

Hello,

In my use case, I have run a **post request** with a list of json ( **json array with object** ) and knowing that this list will be filled in a **dynamic** and **random** way for some data for example for the attribute **idFront** etc and for the attribute **IdRestaurant** and **IdEmployee** id will be retrieved from a **csv file**. All of this is functional for the moment.

 ![probbb.PNG](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/6561c1a02b9a445393e37cce047fd7b9b7062719.png)

Through this figure I want to go to the list for example 30 poiting model for employees for example you have 30 dynamically generated object.  
**The problem is** : that I do not know how instead of repeating the object 30 times, I put a single object and it will take different values for the same request.

 ![pp.PNG](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/66120be5461999dd4e497cf3bc46a016f2ca7bc3.png)

As you can see in the picture I tried with the IdFront attribute but it **extracts** just **one value** for **the first attribute** and for **the second there is no value.**

I need help please

---

<div class="post-metadata">

**Author:** ![sujin\_sam](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@sujin\_sam](https://community.gatling.io/u/sujin_sam)\
**Post date:** [August 24, 2020, 12:18pm UTC](https://community.gatling.io/t/how-to-dynamically-fill-json-array-with-object/5774/2 "2020-08-24T12:18:16Z")

</div>

Hello  
As per the doc [https://gatling.io/docs/current/session/feeder](https://gatling.io/docs/current/session/feeder) , have you tried this?

feed(feeder, 2)

This will provide two values from the csv based on the fetch method(circular, random …)  
we need to substitute like ${idFront1} and ${idFront2}.  
you can give the number as per your need

is this what you expect?

Thanks

---

<div class="post-metadata">

**Author:** ![ghazouani\_nada](https://avatars.discourse-cdn.com/v4/letter/g/c37758/32.png) [@ghazouani\_nada](https://community.gatling.io/u/ghazouani_nada)\
**Post date:** [August 24, 2020, 1:36pm UTC](https://community.gatling.io/t/how-to-dynamically-fill-json-array-with-object/5774/3 "2020-08-24T13:36:06Z")

</div>

Thanks for your help

 ![pppp2.PNG](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/fa002ed94a880129ee73e77da510da96779dc25a.png)

it works now when I used feed (feeder, 2), I got two differenet values.  
But in my case I have **30** object in the json array to fill in, so it is not omptimized to **repeat 30 times** and put **idFront1 until IdFront30**. Is there a more **optimized and simplified way**?

---

<div class="post-metadata">

**Author:** ![sujin\_sam](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@sujin\_sam](https://community.gatling.io/u/sujin_sam)\
**Post date:** [August 25, 2020, 3:56am UTC](https://community.gatling.io/t/how-to-dynamically-fill-json-array-with-object/5774/4 "2020-08-25T03:56:07Z")

</div>

I think we need to write a custom code to loop the feeder and append the list of json object to a String.  
This is just an idea

loop(30){  
 → feeder  
 → append the json object to string  
}  
exec(json string)

by this way we can optimize it.

If you write one, paste the solution here, it will be useful for someone later
