Gatling parameterization

I am using csv feeder data source to paramterize json request body.
csv file:

val csvFeeder = csv(“categories.csv”).random()

val scn = scenario("PetStoreSimulation")
    .exec(http("Catalog #{categoryId}")

below is cat_request json

  "Id": "#{categoryId}",
  "catalogType": "double",

Somehow I get 400 status code .
In most example I have seen ,data is passed in query or formParam of the request. Is there a way to actually pass csv test data to json payload file from the feeder?

400 means Bad Request, ie that your request is malformed.

Your JSON payload is indeed malformed because of a dandling comma.

“Id”: “#{categoryId}”,
“catalogType”: “double”
I made mistake in the json here in the post but nonetheless my json payload used for the request was valid. I assumed probably data from csv was not populated to the json keys. Because when I use static data for categoryId request is successful.
Does Gatling allow to pass paramters(test data ) from csv feeder to json referenced ELFileBody()? Because I need to pass test data record from feeder to request json placeholder variable #{categoryId} and this does not work.

Any chance you’re using an old version of Gatling? Have you tried to upgrade, as required before posting here?

So this is exactly your issue. You’re using the modern Gatling Expression Language syntax with an obsolete Gatling version (3.7.6). Please upgrade. The latest version as of now is 3.9.6.

Yeah thanks I will check that.

Different question, different topic.

Still encountered problem(400 status - malformed request) where csv data is to not passed to the parameters defined in request payload even after updating to gatling version 3.9.6. Below is snippet code of code . Don’t really know what is wrong.

HttpProtocolBuilder httpProtocol = http

 var feeder = csv("data/posts.csv");

        ScenarioBuilder loadScn = scenario("Create post")
                .exec(http("create new post request")


posts.csv (test data source)


create-post.json file (ElFileBody)

  "title": "#{title}",
  "body": "#{content}",
  "userId": "#{userId}"

Hi @Pof,

From your CSV, it seems that userId is a number. But you created a String in your create-post.json file.

Try removing the double quotes around it.

  "title": "#{title}",
  "body": "#{content}",
  "userId": #{userId}


Removing the quotes makes the json file invalid. IDE highlights that file as misconstructed.

Anyways I tried using theJsonFile feeder instead of csv feeder and it is able to pass test data to request payload file.
However Gatling crashes when virtual users does to match feeder records even though I am using the circular strategy .
rampUsersPerSec(1).to(5).during(10) against 4 records in json feeder
Error using circular strategy var feeder = jsonFile(“data/posts.json”).circular()
2023-12-02 14:44:03 ERROR main app.Gatling$ Run crashed
java.lang.reflect.InvocationTargetException: null
at jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance( ~[?:?]
at java.lang.reflect.Constructor.newInstanceWithCaller( ~[?:?]
at java.lang.reflect.Constructor.newInstance( ~[?:?]
at$Java.params(SimulationClass.scala:35) ~[gatling-app-3.9.5.jar:3.9.5]
at ~[gatling-app-3.9.5.jar:3.9.5]
at ~[gatling-app-3.9.5.jar:3.9.5]
at$.start(Gatling.scala:89) ~[gatling-app-3.9.5.jar:3.9.5]
at$.fromMap(Gatling.scala:43) ~[gatling-app-3.9.5.jar:3.9.5]

Error without using any feeder strategy var feeder = jsonFile(“data/posts.json”)
java.lang.IllegalStateException: Feeder json(post.json) is now empty, stopping engine
at io.gatling.core.action.FeedActor$$anonfun$receive$1.applyOrElse(FeedActor.scala:83) ~[gatling-core-3.9.5.jar:3.9.5]

Indeed, what I provided, ie

  "title": "#{title}",
  "body": "#{content}",
  "userId": #{userId}

is not a valid JSON content. It is a template to produce JSON
Keep in mind that gatling will replace data in this template.

For instance (with first value line):

  "title": "foo",
  "body": "bar",
  "userId": 1

That is a valid JSON