I'm trying to make custom body with the result of previous response as a list of strings. So it is a List which is stored as session variable. May i use jsonStringify() method on this session variable? When i use it as is, i've got that JSON is not valid because it pastes list without brackets.
Example:
.body(StringBody(
"""
{
"id": "$id",
"items": $items
}
""".trimIndent()
It sends [item1, item2]
instead of ["item1", "item2"]
I've done this by lambda but i think that was not really good.
.body(StringBody{
session ->
val items = session.get<List<String>>("items")?.map { "\"$it\"" }
val id = session.getString("id")?: "unknown"
"""
{
"id": "$id",
"items": $items
}
""".trimIndent()
Yes you can. Proof: https://github.com/gatling/gatling/blob/main/gatling-core/src/test/scala/io/gatling/core/json/JsonSpec.scala#L73-L76
(some blah blah to meet SoF's 30 chars requirement)