Iterate through string json that was captured as variable. Gatling: 3.11.0 gatling-maven-plugin 4.8.0

Hi dear community. I capture an array as a session variable.
Next i want to get a random index from that array, and save some more values that are located under that index.
I have tried lot of things. Nothing helped.
In the code below the menuArray is the the array I need.
i want somehow to call it as JSON object, in order to make some iterations on it and access some values in it.

object subscribe_menu_by_filter_1 {
  val subscribe_menu_by_filter_1 =  http("subscribe_menu_by_filter_1")
    .post(cache_url+"/api/Publisher/subscribeMenuByFilter")
    .body(ElFileBody("jsonPayload/subscribe_menu_by_filter_1.json")).asJson
    .check(status.is(200))
    .check(jsonPath("$['d']['d'][*]['g']").saveAs("menuArray"))

  val randomExtractor = exec { session =>
    val myArray = session("menuArray").as[String] // Assuming menuArray is a JSON array of strings

//here I need a snippet for making myArray as JSON OBJECT
    session
  }

Please take some time to check the documentation: Gatling checks scripting reference

You’ll see that the jsonPath check comes with a ofXXX (Java/Kotlin) or ofType (Scala) that lets you specify the captured type.

Note: nowadays, we recommend Gatling Java as the default way to go and that Gatling Scala should mostly be used by trained Scala developers.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.