Multiple jsons as paylod

Is it possible to pass the below json array as whole?

When using Stringbody, it requires to hardcode key and when using ElFileBody or RawFileBody, able to pass only on json.

I want to pass the below json array in body. Can someone pls help?

[
{“twitter”: “12”,
“fields”: {
“recent_note”: “asdasdasdasdaasdada”
}
},
{“twitter”: “11”,
“external_id”: 1212,
“last_login”: “2020-12-12”
},
{“twitter”: “11”,
“external_id”: 1212,
“first_login”: “2020-12-12”,
“fields”: {
“city”: “chennai”,
“state”: “tn”,
“phone_numbers”: ["+1221312","+1827981279"]
}
}
]

The content of this e-mail is confidential and is intended solely for the use of the individual or entity to whom it is addressed. If you have received this e-mail by mistake, please reply to this e-mail and follow with its deletion. If you are not the intended recipient, please note that it shall be considered unlawful to copy, forward or in any manner reveal the contents of this e-mail or any part thereof to anyone. Although Freshworks has taken reasonable precautions to ensure no malware is present in this e-mail, Freshworks cannot accept responsibility for any loss or damage arising from the use of this e-mail or attachments.

Try to give a List[Map[String, Any]]

Example:

exec(session => 
  session.set("data", List(
    Map(
      "twitter" -> "12",
      "fields" -> Map("recent_note" -> "asdasdasdasdaasdada")
    ),
    Map(
      "twitter" -> "11",
      "external_id" -> 1212,
      "last_login" -> "2020-12-12"
    ),
    Map(
      "twitter" -> "11",
      "external_id" -> 1212,
      "first_login" -> "2020-12-12",
      "fields" -> Map(
        "city" -> "chennai",
        "state" -> "tn",
        "phone_numbers" -> List("+1221312","+1827981279")
      )
    )
  ))).exec(http("My request").post("my URL").body(StringBody("""${data.jsonStringify()}""").asJson)

Sorry! Reframing the question again. I wanna pass the json object from the json array one at a time. Say

{“twitter”: “12”,
“fields”: {
“recent_note”: “asdasdasdasdaasdada”
}} for one user/ one req

{“twitter”: “11”,
“external_id”: 1212,
“last_login”: “2020-12-12”
} for next req/other consecutive user

setUp(
theScenarioBuilder.inject(atOnceUsers(3)) // in case 3 json objects
).protocols(theHttpProtocolBuilder)

Update: Able to pass the data for single user

val theScenarioBuilder: ScenarioBuilder = scenario(“Scenario1”)
.exec(session => session.set(“data”, List(
Map(
“twitter” → “12”,
“fields” → Map(“recent_note” → “asdasdasdasdaasdada”)
),
Map(
“twitter” → “11”,
“external_id” → 1212,
“last_login” → “2020-12-12”
))))
.foreach("${data}", “contact”) {
exec(
/* myRequest1 is a name that describes the request. */
http(“myRequest1”)
.post("/")
.header(“Content-Type”, “application/json”)
.body(StringBody("""${contact.jsonStringify()}"""))
.asJson)
}

setUp(
theScenarioBuilder.inject(atOnceUsers(1))
).protocols(theHttpProtocolBuilder)

Can you help me achieve this for multi users? I cannot repeat the same data for second user as I have unique fields.

I have figured something more like a hack. If there’s any better solution pls lmk.

val jsonNodes: Array[JsonNode] = new ObjectMapper().readValue(getClass.getResourceAsStream("/contactdata.json"), classOf[Array[JsonNode]])
var count = jsonNodes.length

def getMap(session: Session, jsonNode: Array[JsonNode], countVariable: SessionAttribute): String = {
val contactTocreate = session(“countVariable”).as[Int]
jsonNode.apply(contactTocreate).toString
}

val theScenarioBuilder: ScenarioBuilder = scenario(“Scenario1”)
.repeat(2, “n”) {
exec(session => {
count = count -1
session.set(“countVariable”, count)
})
.exec(session => {
session.set(“counter”, getMap(session, jsonNodes, session(“countVariable”)))
})
.exec(
/* myRequest1 is a name that describes the request. */
http(“myRequest1”)
.post("/")
.header(“Content-Type”, “application/json”)
.body(StringBody("""${counter}""")).asJson)
}

setUp(
theScenarioBuilder.inject(atOnceUsers(2))
).protocols(theHttpProtocolBuilder)

2 users 2 requests each, data obtained from the same file ( contains json array of json obj ) which is processed and stored in jsonNode

What I understand is that you want to feed your user with different data per user => use a feeder

Yeah but it is multiple user multiple requests. feeders work well for multi user single req in my case because I have unique fields in the json and if the same json is used for 2nd time 400 will be thrown