parsing Json

Hi,

how to fetch id values(54674503,66179603,66179595) using jsonpath

{“id”:30,“result”:{“moreRows”:19201,“lList”:[{“id”:“54674503”,“lastUpdate”:“2016-07-15 16:30:21”},{“id”:“66179603”,“lastUpdate”:“2016-07-15 16:30:21”},{“id”:“66179595”,“lastUpdate”:“2016-07-15 16:30:21”}]}}

Thanks in Advance

if you do know there is 3 items, easiest way is:
$…lList[0].id

$…lList[1].id

$…lList[2].id

Hi Nikol,

Thanks for your response,This is not a static no… the no of rows may vary ex (moreRows":19201) .

Hi Manohari,
looks like what you need is here - http://stackoverflow.com/questions/25289334/gatling-looping-through-json-array

Hi,

Yes it looks similar to one u shared it, i tried the same but I’m not sure how to make use of it. Not able to extract id’s from the json. I am able to get the vector list only

.check(jsonPath("$..landmarkList").findAll.saveAs("pList")))
.exec(session => {
  println(session)
  session
})
.foreach("${pList}", "Landmark"){
  exec(session => {
    val id = JsonPath.query("$.id", session("id").as[String]).right.get
    println(id)
    session.set("id", id)
  })}

from the above vector i am not able to get the id's . iam not sure whether i am doing correctly,please help on this

Thanks

Hi

{“id”:30,“result”:{“moreRows”:0,“landmarkList”:[{“id”:“40542263”,“lastUpdate”:“2016-07-15 16:27:45”},{“id”:“40542309”,“lastUpdate”:“2016-07-15 16:27:45”},{“id”:“47891637”,“lastUpdate”:“2016-07-15 16:27:45”},{“id”:“47891639”,“lastUpdate”:“2016-07-15 16:27:45”},{“id”:“40542383”,“lastUpdate”:“2016-07-15 16:27:45”}]}}

how can i get id’s inside landmarkList from the above json

Could you try .check(jsonPath("$…landmarkList…id").findAll.saveAs(“pList”)))

Hi,

 Thanks again , Iam able to get the id's with the below code.but iam getting the output (bolded)

Hi,
Not sure about the “Vector” but you definitely iterate in the wrong place.
Using your code i receive following output:

You can try following:

.check(jsonPath("$..landmarkList..id").ofType[Any].findAll.saveAs("LandmarkIds"))) .exec(session => { val LandmarkId = session("LandmarkIds").as[Seq[Int]] println("check--> " + LandmarkId) session.set("LandmarkId", LandmarkId) })
or

`
.exec(session => {
println(session(“LandmarkIds”).as[String])
session

})
`

and you will receive the same output as above but only 1 string.

About quotes - here you can use foreach and add each item from LandmarkIds with quotes to a new list