jsonPath does not find value in json response body

3,033 views
Skip to first unread message

Nat M

unread,
Aug 8, 2013, 5:10:55 PM8/8/13
to gat...@googlegroups.com
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

Pierre DAL-PRA

unread,
Aug 8, 2013, 5:43:33 PM8/8/13
to gat...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nat M

unread,
Aug 9, 2013, 12:14:35 PM8/9/13
to gat...@googlegroups.com
Hi Pierre,

it worked, thanks do much for your answer!

Kind regards,
Natalie

Spencer Chastain

unread,
Aug 16, 2013, 9:59:41 AM8/16/13
to gat...@googlegroups.com

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


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

Pierre DAL-PRA

unread,
Aug 16, 2013, 3:20:57 PM8/16/13
to gat...@googlegroups.com
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

Stéphane Landelle

unread,
Aug 27, 2013, 6:13:56 AM8/27/13
to gat...@googlegroups.com
Wiki updated, with a link to syntax documentation: http://goessner.net/articles/JsonPath

Cheers,

Stéphane


2013/8/16 Spencer Chastain <secha...@gmail.com>
Reply all
Reply to author
Forward
0 new messages