I managed to get the requests you are looking for sent (although it is still receiving 404, but it could be the server side or the request that your gist sends may not be available). The trick was to completely abandon JsonPath:
.exec(http("Request_10") .get("gatling1") .headers(headers_10) .check(jsonPath("$.result").is("SUCCESS"), jsonPath("$.data[*]").ofType[Map[String,Any]].findAll.saveAs("pList"))) .foreach("${pList}", "player") { exec(session => { val playerMap = session("player").as[Map[String,Any]] val playerId = playerMap("playerId") session.set("playerId", playerId) })
Here, the jsonPath check can automatically save your JSON object as a map, and then you can access the player ID by key. The value type should not be Any ; you can use Int or Long if all your values ββare numbers. If you need more information on what went wrong with jsonPath , read on.
Your first problem is that JsonPath.query() does not just return the value you are looking for. From the JsonPath readme :
JsonPath.query ("$. A", jsonSample) gives you the right one (non-empty iterator). This will allow you to iterate over all possible solutions for the query.
Now that he says Right(non-empty iterator) , I assumed that this means that the iterator is not empty. However, if you try this:
val playerId = JsonPath.query("$.playerId", session("player").as[String]).right.get println(playerId)
... prints an "empty iterator". I'm not sure if this is a problem with jsonPath , jsonPath tag or using somewhere in between, but I lack documentation so that I can insert it.
source share