Strangeness with jsonPath

I created a test file on my local apache server with the following contents:


Then I test it like so:

http( “fetch” )
.get( “http://localhost/data.json” )
.check( jsonPath( “$” ).saveAs( “DATA” ) )
.check( jsonPath( “$.result[*]” ).optional.saveAs( “LIST” ) )
.exec( session => {
println( "DATA = " + session(“DATA”).as[String] )
println( "LIST = " + session(“LIST”).as[String] )


The output looks like this:

DATA = {“result”:[{“id”:1,“name”:“one”},{“id”:2,“name”:“two”},{“id”:3,“name”:“three”}]}
LIST = {“id”:1,“name”:“one”}


I expected it to give me a list, not just the first element. I’ve used this feature before, but suddenly it appears broken, and I don’t think it’s broken in Gatling. I’ve tried varying a bunch of things, trying to figure out what is going on, but I’m not having any luck.

  1. Can you recreate the behavior I am seeing?

  2. Any ideas what I’m doing wrong?

Just like a regex, JsonPath can indeed capture multiple occurrences. But then, the default check cardinality is find:

if you want all the results, use findAll

I knew I was doing something wrong! Thanks, sorry to bug you.