Checking if results array contains value

I have a web service that returns an array, and I’m trying to verify that the array contains a particular value as a check (Gatling 1.x). The array is the entire response (it’s the root element).

I’m quite new to gatling so I’m having issues getting this to work. What I’ve tried is

check(jsonPath("$_").contains(“someValue”))) // the check is chained to the rest of the exec call

I’m getting an error that says error: value contains is not a member of com.excilys.ebi.gatling.http.check.HttpMultipleCheckBuilder[String]. I’m guessing this is happening because jsonPath doesn’t return an array, but I’m not sure what the correct syntax is for this.



$_ is not a valid JsonPath expression. Please have a look at the spec and try some online tester, such as this one:

If you want to collect all the values, the correct path is “$…*”. However, we don’t currently have a “contains” check. The reason is that we expect users to do this filtering in the expression.

So, what you have to do is design a proper JsonPath expression that will only succeed when your condition regarding “someValue” holds, and use the regular/default “exists”.



Thanks for the quick reply. The reason I was trying the underscore was from a note on the gatling wiki page that says

In JSON, the root element has no name. This might be a problem when it’s an array and one want to target its elements. As a workaround, Gatling names it _.

Am I misunderstanding what that means?

But to the rest of your reply, that makes sense. I’ll give that a try - thanks again.

Ah, OK :slight_smile:

That was a long long time ago, when we were using another syntax, more similar to XPath.
We switched along the way to the standard one.

Got it, thanks for clarifying. I’ll try the way you suggested.

I think I still might be missing something. My returned data looks like:

And my check expression is


That check is not passing.

But if i put it in that jsonPath tester (from the link you gave), then it works just fine…

It seems that this javascript implementation allows the use of double quotes instead of the regular simple ones, which we don’t.


Worked perfectly, thanks.

Have fun