# jsonPath selector

**URL:** <https://community.gatling.io/t/jsonpath-selector/163>\
**Category:** Gatling (Open-Source)\
**Created:** [November 13, 2012, 2:36pm UTC](https://community.gatling.io/t/jsonpath-selector/163 "2012-11-13T14:36:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@Christophe](https://community.gatling.io/u/Christophe)\
**Post date:** [November 13, 2012, 2:36pm UTC](https://community.gatling.io/t/jsonpath-selector/163/1 "2012-11-13T14:36:04Z")

</div>

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

```auto

```

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA1](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@Pierre\_DAL-PRA1](https://community.gatling.io/u/Pierre_DAL-PRA1)\
**Post date:** [November 13, 2012, 2:52pm UTC](https://community.gatling.io/t/jsonpath-selector/163/2 "2012-11-13T14:52:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christophe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@Christophe](https://community.gatling.io/u/Christophe)\
**Post date:** [November 13, 2012, 4:21pm UTC](https://community.gatling.io/t/jsonpath-selector/163/3 "2012-11-13T16:21:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christophe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@Christophe](https://community.gatling.io/u/Christophe)\
**Post date:** [November 14, 2012, 9:15am UTC](https://community.gatling.io/t/jsonpath-selector/163/4 "2012-11-14T09:15:59Z")

</div>

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

---

<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:** [November 14, 2012, 10:44am UTC](https://community.gatling.io/t/jsonpath-selector/163/5 "2012-11-14T10:44:03Z")

</div>

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](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/](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

---

<div class="post-metadata">

**Author:** ![Christophe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@Christophe](https://community.gatling.io/u/Christophe)\
**Post date:** [November 14, 2012, 2:53pm UTC](https://community.gatling.io/t/jsonpath-selector/163/6 "2012-11-14T14:53:43Z")

</div>

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 !

---

<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:** [November 14, 2012, 3:09pm UTC](https://community.gatling.io/t/jsonpath-selector/163/7 "2012-11-14T15:09:40Z")

</div>

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
