Feed multiple n-rows from CSV to json payload

Hi,
I want to load n-rows from the csv file to .json file
Example :
in my CSV I have the Below data with header planetNames:

planetNames
Mercury
VENUS
Earth
Mars
Jupiter
Saturn

in the code

val planetFeeder = csv(“data/DataVolume/planets.csv”).random

private val planetsRequest = exec(_.set(“token”, AccessToken))
.feed(planetFeeder, 2)
.exec(http(“PlanetREquests”)
.post(“example-request”)
.headers(Map(“Accept” → “application/json”, “Content-Type” → “application/json”))
.body(ElFileBody(“System/planetFile.json”))
.check(status.is(200))

Below is body of planetFile.json file :
[#{planetNames}]

When tried to feed multiple rows in my .json file with the above attribute it fails with the below error

00:39:25.049 [ERROR] i.g.h.a.HttpRequestAction - ‘httpRequest-1’ failed to execute: No attribute named ‘planetNames’ is defined

Looks correct to me, except for the JSON serialization for which you should use jsonStringify(), but that wouldn’t explain the “No attribute” error.
Please provide a full reproducer as a project on Github.

But if i provide as below then it works perfectly.

with .feed(planetFeeder, 2), i believe the session names would be:

  • planetNames1
  • planetNames2
1 Like

Thanks @shade this worked. Thanks for the solution.

-A

OK, this is a typical example as to why we request that you use an up-to-date version of Gatling before opening threads here: How to Ask a Question

The behavior has changed in Gatling 3.8, see Gatling - Upgrading from 3.7 to 3.8

  • #4226: The feed override that takes a number of entries now produces arrays instead of translating the keys with an index suffix.

So:

  • with Gatling <= 3.7 => indeed, you have planetNames1 and planetNames2
  • with Gatling >= 3.8 => you have a planetNames array whose entries you can access with #{planetNames(0)} and #{planetNames(1)}, or just directly use the array with #{planetNames}
1 Like

If someone want to see example in Java for this case, please visit:
Case0015UUIDfeederTwoRecordsAtTheSameTimeSimulation

1 Like