# parsing Json

**URL:** <https://community.gatling.io/t/parsing-json/3169>\
**Category:** Gatling (Open-Source)\
**Created:** [August 2, 2016, 9:43am UTC](https://community.gatling.io/t/parsing-json/3169 "2016-08-02T09:43:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manohari](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Manohari](https://community.gatling.io/u/Manohari)\
**Post date:** [August 2, 2016, 9:43am UTC](https://community.gatling.io/t/parsing-json/3169/1 "2016-08-02T09:43:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nikolay\_Degkin](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@Nikolay\_Degkin](https://community.gatling.io/u/Nikolay_Degkin)\
**Post date:** [August 2, 2016, 3:30pm UTC](https://community.gatling.io/t/parsing-json/3169/2 "2016-08-02T15:30:39Z")

</div>

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

$…lList[1].id

$…lList[2].id

---

<div class="post-metadata">

**Author:** ![Manohari](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Manohari](https://community.gatling.io/u/Manohari)\
**Post date:** [August 3, 2016, 5:27am UTC](https://community.gatling.io/t/parsing-json/3169/3 "2016-08-03T05:27:11Z")

</div>

Hi Nikol,

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

---

<div class="post-metadata">

**Author:** ![Nikolay\_Degkin](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@Nikolay\_Degkin](https://community.gatling.io/u/Nikolay_Degkin)\
**Post date:** [August 3, 2016, 9:22am UTC](https://community.gatling.io/t/parsing-json/3169/4 "2016-08-03T09:22:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Manohari](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Manohari](https://community.gatling.io/u/Manohari)\
**Post date:** [August 4, 2016, 11:51am UTC](https://community.gatling.io/t/parsing-json/3169/5 "2016-08-04T11:51:53Z")

</div>

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

```auto
.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)
  })}

```

```auto

```

```auto
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

```

```auto

```

```auto
Thanks

```

```auto

```

---

<div class="post-metadata">

**Author:** ![Manohari](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Manohari](https://community.gatling.io/u/Manohari)\
**Post date:** [August 8, 2016, 10:31am UTC](https://community.gatling.io/t/parsing-json/3169/6 "2016-08-08T10:31:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nikolay\_Degkin](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@Nikolay\_Degkin](https://community.gatling.io/u/Nikolay_Degkin)\
**Post date:** [August 8, 2016, 2:41pm UTC](https://community.gatling.io/t/parsing-json/3169/7 "2016-08-08T14:41:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Manohari](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Manohari](https://community.gatling.io/u/Manohari)\
**Post date:** [August 9, 2016, 6:22am UTC](https://community.gatling.io/t/parsing-json/3169/8 "2016-08-09T06:22:26Z")

</div>

```auto
Hi,

```

```auto

```

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

```

---

<div class="post-metadata">

**Author:** ![Nikolay\_Degkin](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@Nikolay\_Degkin](https://community.gatling.io/u/Nikolay_Degkin)\
**Post date:** [August 10, 2016, 9:02am UTC](https://community.gatling.io/t/parsing-json/3169/9 "2016-08-10T09:02:52Z")

</div>

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

[![](https://lh3.googleusercontent.com/-wfkVgRDVI2A/V6oCDVhlfpI/AAAAAAAABJ4/DFhiAw5_kfkl7XWX1s2WTy8kyE-6oIREQCLcB/s320/CWindowssystem32cmd.jpg)](https://lh3.googleusercontent.com/-wfkVgRDVI2A/V6oCDVhlfpI/AAAAAAAABJ4/DFhiAw5_kfkl7XWX1s2WTy8kyE-6oIREQCLcB/s1600/CWindowssystem32cmd.jpg)

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
