jsonPath does not find value in json response body

Good afternoon,

I build this check to get an id from the json response body using jsonpath:

.exec(http(“request_3”)
.post("""/api/sync/210/xyz""")
.headers(headers_1)
.body(RawFileBody(“request_3.txt”))
.check(jsonPath("/objects/id").find.saveAs(“jl_id”)))

When running the simulation I can see this error message:

Request:
request_3: KO jsonPath(/objects/id).exists() didn’t match: found nothing

Json response body is below:

body=
[{
“stamp”:1376054247,
“objects”:[{
“xid”:“x-coredata://6C9AA7E9-xxxBD7E3FA0/TechLog/pXYZ”,
“id”:11055
}]
}]

I need to extract “11055” and save it as a session parameter. Any ideas why this is not working?

I am using Gatling 2.

Many thanks,
Nat

Hi,

Before Gatling 1.5 , jsonPath use the XPath syntax, and your expression would have worked back then.
But since Gatling 1.5 (and therefore Gatling 2), we are using the proper JSONPath syntax, which is described here : http://goessner.net/articles/JsonPath/ .
You can use this site if you want to check your expressions : http://jsonpath.curiousconcept.com/

In your case, the correct JSONPath expression would be : $[0].objects[0].id ( this one would work too : $…id )

Cheers,

Pierre

Hi Pierre,

it worked, thanks do much for your answer!

Kind regards,
Natalie

Could we get the docs on the gatling github page updated with this information:

https://github.com/excilys/gatling/wiki/Checks#wiki-json

(Doesn’t look like the wiki is open for everyone to edit, otherwise I’d have done it myself)

Sure, will do !

There is some info about the JsonPath syntax change in the Changelog, but it’s missing in Checks…

We plan to move away from Github’s wiki for the documentation to a fully-fledged documentation system, which would allow PRs on documentation.

Cheers,

Pierre

Wiki updated, with a link to syntax documentation: http://goessner.net/articles/JsonPath

Cheers,

Stéphane