jsonPath selector

Hello,

I am using Gatling to load test a REST API.
I am kinda lost with the jsonPath selector.

Here is an example of json message I want to parse with Gatling :

[
{
“id”:19434,
“company”:
{
“id”:18971
},
“owner”:
{
“id”:18957,
},
“process”:
{
“id”:18972
}
},
{
“id”:19435,
“company”:
{
“id”:18972
},
“owner”:
{
“id”:18957,
},
“process”:
{
“id”:18974
}
}
]

I want to extract all the 1st levels ids (in this case 19434 & 19434)

I tried the following jsonPath expression : jsonPath("//id").findAll.saveAs(“ids”), but it returned all the ids (8 elements with my example)

Any idea how I could select only the first level ids ?

Thanks


Your jsonPath expression search all “id” elements, whatever their depth is.
Can you try this expression : /*/id ?

Thanks Pierre,

But when i use /*/id I get this error :

[ERROR] [11/13/2012 17:20:40.211] [GatlingSystem-akka.actor.default-dispatcher-1] [akka://GatlingSystem/user/$g/$a] null
java.lang.UnsupportedOperationException
at com.excilys.ebi.gatling.core.check.extractor.jsonpath.JacksonNavigator.getElementName(JacksonNavigator.scala:67)
at com.excilys.ebi.gatling.core.check.extractor.jsonpath.JacksonNavigator.getElementName(JacksonNavigator.scala:26)
at org.jaxen.expr.DefaultNameStep.matches(DefaultNameStep.java:327)

Regards,

Christophe

I tried another solution :

jsonPath("//id[count(ancestor::*)=1]")

Select all the id element with only 1 ancestor, but I encounter the following error :

Caused by: org.jaxen.UnsupportedAxisException: parent
at org.jaxen.DefaultNavigator.getParentAxisIterator(DefaultNavigator.java:115)
at org.jaxen.DefaultNavigator.getParentNode(DefaultNavigator.java:261)

As it is stated in the documentation :

Similar to XPath 1.0, but to be applied on a JSON response body. It is intended for capturing leaves of the JSON tree, so only a subset of XPath is supported.

Gatling developers, could you please specify what is the subset of XPath that is actually supported ?

Thanks

Christophe

Hi Christophe,

I properly implemented the wildcard support, so you should be fine with the snapshot that should appear in about 20 minutes on cloudbees:
https://github.com/excilys/gatling/issues/820

http://repository-gatling.forge.cloudbees.com/snapshot/com/excilys/ebi/gatling/highcharts/gatling-charts-highcharts/1.4.0-SNAPSHOT/

I haven’t tried to play with child/ancestor thought.

Cheers,

Stéphane

I’ve tried the latest snapshot, it works !

Strangely I don’t use the wildcard, the following code :

jsonPath("/id")

works correctly with 1.4 and fails with 1.3.4 ?

Anyway, many thanks for the quick fix !

Cool!

I think we will have to think deeper on how we map the json model to the xml one before releasing 1.4.0.
It possible that by then, maybe only one of “/id” and “/*/id” will work for your use case.
So, stay tuned.

Cheers,

Stéphane