# JsonPath doesn't accept @

**URL:** <https://community.gatling.io/t/jsonpath-doesnt-accept/1489>\
**Category:** Gatling (Open-Source)\
**Created:** [September 30, 2014, 1:47pm UTC](https://community.gatling.io/t/jsonpath-doesnt-accept/1489 "2014-09-30T13:47:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![COTTET\_Julien](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@COTTET\_Julien](https://community.gatling.io/u/COTTET_Julien)\
**Post date:** [September 30, 2014, 1:47pm UTC](https://community.gatling.io/t/jsonpath-doesnt-accept/1489/1 "2014-09-30T13:47:21Z")

</div>

Hello,

I’m trying to do a jsonPathCheck but it seems not to work with my regex.

The code below

JsonPath.query("$.object[\*].@id","{“object”: [{"@id": “3”,“nom”: “object3”}]}")

produce the response below

Left(JPError(string matching regex `[$_\p{L}][$_\-\d\p{L}]*' expected but `@’ found))

{  
“object”: [  
{  
“@id”: “3”,  
“nom”: “object3”  
}]  
}

---

<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:** [September 30, 2014, 1:54pm UTC](https://community.gatling.io/t/jsonpath-doesnt-accept/1489/2 "2014-09-30T13:54:06Z")

</div>

So you’re trying to directly use our JsonPath implementation, not through Gatling APIs, right?

JsonPath.query second element is an AST, not a String =\> a tree of Maps and Lists that have already been parsed.

---

<div class="post-metadata">

**Author:** ![COTTET\_Julien](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@COTTET\_Julien](https://community.gatling.io/u/COTTET_Julien)\
**Post date:** [September 30, 2014, 2:03pm UTC](https://community.gatling.io/t/jsonpath-doesnt-accept/1489/3 "2014-09-30T14:03:09Z")

</div>

I use the check of Gatling in the way below :  
I’v replaced below the real args by “…”.  
But i’ve the same result with JsonPath.query(…)

That code worked well with the version : 2.0.0-M3a but not with 2.0.0-RC6

.exec(http("…")  
.get("…")  
.headers(Map(“token” → “${token}”))  
.check([status.is](http://status.is)(200))

.check(jsonPath("$.object[\*].@id").findAll.saveAs(“IDS\_OBJECT”)))

---

<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:** [September 30, 2014, 2:15pm UTC](https://community.gatling.io/t/jsonpath-doesnt-accept/1489/4 "2014-09-30T14:15:55Z")

</div>

2M3a was using Jayway’s JsonPath implementation, which is both inefficient and broken (doesn’t respect the jsonPath specification).  
So we implemented our own.

$.object[\*].@id is not a valid expression as [@ is a reserved character in JsonPath](http://goessner.net/articles/JsonPath/): “the current object/element”. Basically, it shouldn’t have worked in the first place.

As a consequence, you have to use the bracket notation so you can pass the attribute name in a protected String:  
$.object[\*][’@id’]

---

<div class="post-metadata">

**Author:** ![COTTET\_Julien](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@COTTET\_Julien](https://community.gatling.io/u/COTTET_Julien)\
**Post date:** [September 30, 2014, 2:55pm UTC](https://community.gatling.io/t/jsonpath-doesnt-accept/1489/5 "2014-09-30T14:55:02Z")

</div>

Thanks for your answers.

I know it, but I did not want to do it now.  
I will have to refactor some pieces of code to avoid the ‘@’ char.

It doesn’t work with [’@id’]

---

<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:** [September 30, 2014, 3:01pm UTC](https://community.gatling.io/t/jsonpath-doesnt-accept/1489/6 "2014-09-30T15:01:57Z")

</div>

> It doesn't work with ['@id']

Well, I really looks to me that it does:

> <https://github.com/gatling/gatling/commit/c7ac706cc21da2fa6913544bd1a84e1f6d47948b>

Are you sure you don't have a typo on your side such as a dot between the  
brackets?

Proper path is $.object[\*]['@id']

---

<div class="post-metadata">

**Author:** ![COTTET\_Julien](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@COTTET\_Julien](https://community.gatling.io/u/COTTET_Julien)\
**Post date:** [October 1, 2014, 7:06am UTC](https://community.gatling.io/t/jsonpath-doesnt-accept/1489/7 "2014-10-01T07:06:59Z")

</div>

Thanks a lot, you were right with the dot.

My job works fine now.
