jsonPath selector

1,109 views
Skip to first unread message

Christophe

unread,
Nov 13, 2012, 9:36:04 AM11/13/12
to gat...@googlegroups.com
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




Pierre DAL-PRA

unread,
Nov 13, 2012, 9:52:59 AM11/13/12
to gat...@googlegroups.com
Your jsonPath expression search all "id" elements, whatever their depth is.
Can you try this expression : /*/id ?

Christophe

unread,
Nov 13, 2012, 11:21:58 AM11/13/12
to gat...@googlegroups.com
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

Christophe

unread,
Nov 14, 2012, 4:15:59 AM11/14/12
to gat...@googlegroups.com
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

Stéphane Landelle

unread,
Nov 14, 2012, 5:44:03 AM11/14/12
to gat...@googlegroups.com
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:

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

Cheers,

Stéphane


2012/11/14 Christophe <chp...@gmail.com>

Christophe

unread,
Nov 14, 2012, 9:53:43 AM11/14/12
to gat...@googlegroups.com
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 !

Stéphane Landelle

unread,
Nov 14, 2012, 10:09:40 AM11/14/12
to gat...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages