# jsonPath and array

**URL:** https://community.gatling.io/t/jsonpath-and-array/974
**Category:** Gatling (Open-Source)
**Created:** [April 23, 2014, 12:49pm UTC](https://community.gatling.io/t/jsonpath-and-array/974 "2014-04-23T12:49:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![E\_Ulrich\_Kriegel](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@E\_Ulrich\_Kriegel](https://community.gatling.io/u/E_Ulrich_Kriegel)
#### Post date: [April 23, 2014, 12:49pm UTC](https://community.gatling.io/t/jsonpath-and-array/974/1 "2014-04-23T12:49:09Z")

</div>

Hi there,  
my REST-Service returns

{“index”:[{“provider\_id”:“foo”,“etag”:“f77d14f2549485c4e087d3d7b1250cbd77b7da24”},{“provider\_id”:“baz”,“etag”:“7de32bc8c614165c0c3a62dfda238cec0d7a5139”}]}

The expression $.index[\*].provider\_id should return (and the expression checker [http://jsonpath.curiousconcept.com](http://jsonpath.curiousconcept.com/) does)  
[  
“foo”,  
“baz”  
]

bat returns “baz” only

–Ulrich

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [April 23, 2014, 1:06pm UTC](https://community.gatling.io/t/jsonpath-and-array/974/2 "2014-04-23T13:06:14Z")

</div>

Which version of Gatling are you using ?

---

<div class="post-metadata">

### Author: ![E\_Ulrich\_Kriegel](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@E\_Ulrich\_Kriegel](https://community.gatling.io/u/E_Ulrich_Kriegel)
#### Post date: [April 23, 2014, 1:08pm UTC](https://community.gatling.io/t/jsonpath-and-array/974/3 "2014-04-23T13:08:06Z")

</div>

Sorry,  
Gatling2 Snapshot checked out April, 12th

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [April 23, 2014, 1:15pm UTC](https://community.gatling.io/t/jsonpath-and-array/974/4 "2014-04-23T13:15:48Z")

</div>

“Mailing-list test case” should “work” in {  
val json= parseJson( “”"{“index”:[{“provider\_id”:“foo”,“etag”:“f77d14f2549485c4e087d3d7b1250cbd77b7da24”},{“provider\_id”:“baz”,“etag”:“7de32bc8c614165c0c3a62dfda238cec0d7a5139”}]}""")  
JsonPath.query( “$.index[\*].provider\_id”, json) should findElements(text(“foo”), text(“baz”))  
}

With the last JsonPath engine, the following unit test is working fine.  
Can you

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [April 23, 2014, 1:17pm UTC](https://community.gatling.io/t/jsonpath-and-array/974/5 "2014-04-23T13:17:17Z")

</div>

“Mailing-list test case” should “work” in {  
val json= parseJson( “”"{“index”:[{“provider\_id”:“foo”,“etag”:“f77d14f2549485c4e087d3d7b1250cbd77b7da24”},{“provider\_id”:“baz”,“etag”:“7de32bc8c614165c0c3a62dfda238cec0d7a5139”}]}""")  
JsonPath.query( “$.index[\*].provider\_id”, json) should findElements(text(“foo”), text(“baz”))  
}

With the last JsonPath engine, the following unit test is working fine.  
Can you show me the associated Gatling script?  
How do you come to the conclusion that the jsonPath() check isn’t working as expected ?

Regards  
Nicolas

---

<div class="post-metadata">

### Author: ![E\_Ulrich\_Kriegel](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@E\_Ulrich\_Kriegel](https://community.gatling.io/u/E_Ulrich_Kriegel)
#### Post date: [April 23, 2014, 1:28pm UTC](https://community.gatling.io/t/jsonpath-and-array/974/6 "2014-04-23T13:28:08Z")

</div>

Hi Nicolas,

here comes the scenario definition:

val scn = scenario(“get service areas”)

.feed(ssv(“gabriel/devices.ssv”).circular)

.exec(

http(“get service\_areas”)

.get("/service\_areas")

.headers(Headers.default)

.header(“X-KWRN-Device-ID”,"${deviceId}")

.check(jsonPath("$.index[\*].provider\_id")

.saveAs(“providerIdList”))

.check(header(“Etag”).saveAs(“Etag”))

.check(status.saveAs(“status”), status.is(200)))

.exec(session=\>{println(session)

session})

I simply printed the session, and providerIdList is in any case “foo”, the first element of the array

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [April 23, 2014, 1:30pm UTC](https://community.gatling.io/t/jsonpath-and-array/974/7 "2014-04-23T13:30:54Z")

</div>

Would you mind trying again with the extra “.findAll”:

.check(jsonPath("$.index[\*].provider\_id").findAll.saveAs(“providerIdList”))

Thanks  
Nicolas

---

<div class="post-metadata">

### Author: ![E\_Ulrich\_Kriegel](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@E\_Ulrich\_Kriegel](https://community.gatling.io/u/E_Ulrich_Kriegel)
#### Post date: [April 23, 2014, 1:33pm UTC](https://community.gatling.io/t/jsonpath-and-array/974/8 "2014-04-23T13:33:07Z")

</div>

Thanks
