How to save the captured jsonPath in list instead of variable

My use case is I am parsing a json and getting a list.Based on list values I and querying an api and capture the value from jsonpath .I want to replace all the captured values in json, so its easier if that’s a list where I can be flexible defining the capacity

Thanks
Sandeep

Hello
Can you pls share a code snippet and explain ?

Thanks
Sam

Sure,relevant code snippets are below.I am new to gatling

Defining var count and comp for resetting count =0 when we loop over a new list to capture the jsonpath

var count = new java.util.concurrent.atomic.AtomicInteger(0)

val comp = new java.util.concurrent.atomic.AtomicInteger(0)
Getting List size correctly

. exec(

session => {

val wid_id = session(“list”).as[Seq[Any]].size

session.set(“wid_id”, wid_id)

}

).exec({ session =>

// val filename = session(“filename”).asOption[String].toString

wid_id = session(“wid_id”).as[Int] //counter

println(“wid_id is”+wid_id+" ")

session})

.exec({session=>

count.set(0)

session})

Code of Interest
Looping over list

.exec({session=>

count.set(0)

session})

.repeat("${wid_id}"){

// .foreach("${list}", “field”, “0”){

//resetting loop when i enter repeat loop for first time

doIf(count.equals(comp)) {

exec({session =>

println(“inside loop”)

session.set(“random”,count.set(0))})

.exec(_.set(test, “fail”))

}

exec(session => {

session.set(“field”, list(count.intValue())).set(index, “wid” + count.get())

})

.exec({ session =>

println("list element is " + list(count.intValue()) + " wid index is " + wid(count.intValue()) + " index is " + count.intValue())

session

})

.exec(http(“Fields Lookup”)

.get("/ots/super/services/wql/v1/dataSources/${datasourceId}/fields?offset=0&limit=100")

.headers(Map(“X-Workday-Client” → “0”, “Session-Secure-Token” → “${csrfToken}”, “Content-Type” → “application/json”

, “Authorization” → auth))

.check(

status.is(200)

).check(jsonPath("$.data[?(@.descriptor == “${field}”)].id").find.saveAs(“wid”+count.get().toString))) //want to capture jsonPath in wid0 ,wid1 ,wid2 variables

.exec({ session =>

count.getAndIncrement()

session

})

Thanks

Sandeep

The problem is i need to reset count when i enter loop which is not happening.Can anyone help on this please?

Hi,

You can write the statement in this way.

doIf(count.equals(comp)) {

exec({session =>

println(“inside loop”)

session.set(“random”,count.set(0))})

.set(test, “fail”)

}

Thanks Abinash.
How to capture jsonpath iteratively, like in dynamic string based on iterator value" …wid0,wid1,wid2 etc