# jsonPath woes

**URL:** <https://community.gatling.io/t/jsonpath-woes/800>\
**Category:** Gatling (Open-Source)\
**Created:** [January 30, 2014, 1:40pm UTC](https://community.gatling.io/t/jsonpath-woes/800 "2014-01-30T13:40:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Alan\_Ryan](https://community.gatling.io/u/Alan_Ryan)\
**Post date:** [January 30, 2014, 1:40pm UTC](https://community.gatling.io/t/jsonpath-woes/800/1 "2014-01-30T13:40:55Z")

</div>

Hi,

I have the JSON below returned from a Restful call, when I use JSONPath tool, I can extract the values I need via:

**$…searchResults.file[\*].link[0].$**

giving me:

_[_  
_“[http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg](http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg)”,_  
_“[http://url/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg](http://url/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg)”_  
_]_

But I cannot repeat the same with Gatling’s jsonPath, using the following to check the result of my HTTP call.

.check(jsonPath("$…searchResults.file.link[0].$")  
.findAll  
.saveAs(“userFiles”))

gives the entire link element as results

No protocol.baseURL defined but provided url is relative : {"$":"_“[http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg](http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg)”,_","@rel":“file”}

. However …searchResults.file.link[0].@rel works fine in returning

[  
“file”,  
“file”  
]

Stumped…

Al

{  
“searchResults”: {  
“@xmlns”: {  
“dvi”: “[http://internal.x/ns/1.0](http://internal.x/ns/1.0)”,  
“$”: “[http://y/ns/1.0](http://y/ns/1.0)”,  
“a”: “[http://z/ns/1.0](http://z/ns/1.0)”  
},  
“@totalCount”: “26”,  
“link”: {  
“@rel”: “next”,  
“$”: “[http://next/next.html](http://next/next.html)”  
},  
“file”: [  
{  
“link”: [  
{  
“@rel”: “file”,  
“$”: “[http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg](http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg)”  
}

]  
},  
{  
“link”: [  
{  
“@rel”: “file”,  
“$”: “[http://url/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg](http://url/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg)”  
}  
]  
}  
]  
}  
}

---

<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:** [January 30, 2014, 1:59pm UTC](https://community.gatling.io/t/jsonpath-woes/800/2 "2014-01-30T13:59:24Z")

</div>

Hi,

So, you said that you check this expression **$…searchResults.file[\*].link[0].$**  
But in the Gatling, scenario, you don’t use the same one, .check(jsonPath("$…searchResults. **file**.link[0].$")

Could you try again with .check(jsonPath("$…searchResults.**file[\*]**.link[0].$") ?

cheers  
Nicolas

---

<div class="post-metadata">

**Author:** ![Alan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Alan\_Ryan](https://community.gatling.io/u/Alan_Ryan)\
**Post date:** [January 30, 2014, 2:05pm UTC](https://community.gatling.io/t/jsonpath-woes/800/3 "2014-01-30T14:05:54Z")

</div>

Hi Sorry, just a typo - it gives the same results:

14:05:00.701 [ERROR] i.g.h.a.HttpRequestAction - No protocol.baseURL defined but provided url is relative : {"$":“[http://............","@rel](http://............%22,%22@rel)”:“file”}

Al

---

<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:** [January 30, 2014, 2:21pm UTC](https://community.gatling.io/t/jsonpath-woes/800/4 "2014-01-30T14:21:16Z")

</div>

Which version of Gatling are you using ?

---

<div class="post-metadata">

**Author:** ![Alan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Alan\_Ryan](https://community.gatling.io/u/Alan_Ryan)\
**Post date:** [January 30, 2014, 2:30pm UTC](https://community.gatling.io/t/jsonpath-woes/800/5 "2014-01-30T14:30:30Z")

</div>

2.0.0-M3a

thought I’d go with the bleeding edge 😉

---

<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:** [January 30, 2014, 2:46pm UTC](https://community.gatling.io/t/jsonpath-woes/800/6 "2014-01-30T14:46:44Z")

</div>

We haven’t released the M4 milestone, but we are getting close to it.  
Can I ask you to try with the last Snapshot version ? [https://oss.sonatype.org/content/repositories/snapshots/io/gatling/highcharts/gatling-charts-highcharts/2.0.0-SNAPSHOT/](https://oss.sonatype.org/content/repositories/snapshots/io/gatling/highcharts/gatling-charts-highcharts/2.0.0-SNAPSHOT/)

The JsonPath part has been rewritten from scratch using our own engine, [https://github.com/gatling/jsonpath](https://github.com/gatling/jsonpath). We had too many issues like the own you describe. I have checked and your JsonPath expression is correctly resolved with this version.

cheers  
Nicolas

---

<div class="post-metadata">

**Author:** ![Alan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Alan\_Ryan](https://community.gatling.io/u/Alan_Ryan)\
**Post date:** [January 30, 2014, 3:52pm UTC](https://community.gatling.io/t/jsonpath-woes/800/7 "2014-01-30T15:52:32Z")

</div>

Hi Nicolas,

That seems to work, many thanks.

Al

---

<div class="post-metadata">

**Author:** ![Alan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Alan\_Ryan](https://community.gatling.io/u/Alan_Ryan)\
**Post date:** [January 30, 2014, 4:49pm UTC](https://community.gatling.io/t/jsonpath-woes/800/8 "2014-01-30T16:49:49Z")

</div>

Nicolas, One more quick question about the new SNAPSHOT version I am using.

When I code:

```auto
setUp(scn.inject(nothingFor(4 seconds),
                 atOnce(10 users),
                ramp(10 users) over (5 seconds),

```

I get a:

…not found: value atOnce  
16:47:30.720 [ERROR] i.g.a.ZincCompiler$ - atOnce(25 users),  
16:47:30.721 [ERROR] i.g.a.ZincCompiler$ - ^

but I seem to be using a 2.x build

?

Alan

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [January 30, 2014, 4:52pm UTC](https://community.gatling.io/t/jsonpath-woes/800/9 "2014-01-30T16:52:30Z")

</div>

Syntax changed.  
atOnce =\> atOnceUsers  
ramp =\> rampUsers

---

<div class="post-metadata">

**Author:** ![Alan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Alan\_Ryan](https://community.gatling.io/u/Alan_Ryan)\
**Post date:** [January 30, 2014, 6:07pm UTC](https://community.gatling.io/t/jsonpath-woes/800/10 "2014-01-30T18:07:55Z")

</div>

doh… thanks 😉

---

<div class="post-metadata">

**Author:** ![Alan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Alan\_Ryan](https://community.gatling.io/u/Alan_Ryan)\
**Post date:** [February 6, 2014, 3:59pm UTC](https://community.gatling.io/t/jsonpath-woes/800/11 "2014-02-06T15:59:11Z")

</div>

Hi, Since I changed to the SNAPSHOT version mentioned [above](https://www.google.com/url?q=https%3A%2F%2Foss.sonatype.org%2Fcontent%2Frepositories%2Fsnapshots%2Fio%2Fgatling%2Fhighcharts%2Fgatling-charts-highcharts%2F2.0.0-SNAPSHOT%2F&sa=D&sntz=1&usg=AFQjCNEKafEOQfpf4UzvkGBqM8AqulJTSQ), I have been unable to Log my responses for debugging purposes.

I get this error

15:50:09.965 [ERROR] i.g.a.ZincCompiler$ - /home/alan/devel/gatling/gatling-charts-highcharts-2.0.0-SNAPSHOT/user-files/simulations/pac/ValidateV2.scala:15: value getResponseBody is not a member of io.gatling.http.response.Response  
15:50:09.988 [ERROR] i.g.a.ZincCompiler$ - println(“Response Type:” + response.getResponseBody())

for this code:

val httpP = http  
.extraInfoExtractor((callId,status,session,request,response) =\> {

println(“Call:” + callId)  
println("URL " + request.getUrl())  
println(“Response Type:” + response.getResponseBody())  
Nil  
})

If I just dump the response object, I can see it is an instance of [NettyResponse](http://asynchttpclient.github.io/async-http-client/apidocs/reference/com/ning/http/client/providers/netty/NettyResponse.html) which seems to have this method?

//'scuse my Java lingo

Alan

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [February 6, 2014, 4:08pm UTC](https://community.gatling.io/t/jsonpath-woes/800/12 "2014-02-06T16:08:21Z")

</div>

We now have our own Response API which is different from the AHC one.  
This way, we have a better control on how the chunks are used.

Now, response has a body which is of type ResponseBody:  
[https://github.com/excilys/gatling/blob/master/gatling-http/src/main/scala/io/gatling/http/response/Response.scala#L48](https://github.com/excilys/gatling/blob/master/gatling-http/src/main/scala/io/gatling/http/response/Response.scala#L48)

And ResponseBody has string, stream and bytes methods:  
[https://github.com/excilys/gatling/blob/master/gatling-http/src/main/scala/io/gatling/http/response/ResponseBody.scala#L87-L91](https://github.com/excilys/gatling/blob/master/gatling-http/src/main/scala/io/gatling/http/response/ResponseBody.scala#L87-L91)

So, what you need is response.body.string.

---

<div class="post-metadata">

**Author:** ![Alan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Alan\_Ryan](https://community.gatling.io/u/Alan_Ryan)\
**Post date:** [February 10, 2014, 2:48pm UTC](https://community.gatling.io/t/jsonpath-woes/800/13 "2014-02-10T14:48:42Z")

</div>

Hi,

Thanks for the quick response as always. This worked once I grabbed the latest snapshot.

Al
