Retrieving json data two arrays deep

Hi,

I have json data that looks like the following

`
[
{
id:12345,
details: [
{
id: 89823
},

]
},

]

`

I need to do the following:

Take a random element in the first array, save its id, then pick a random element in the details and save that id. I am having quite a hard at doing that with Gatling and Scala.

I have this code:

`

val browse = exec(http(“API Call”)
.get("/someuri").asJSON
.check(status.is(200), jsonPath("$").ofType[Seq[Any]].findAll.saveAs(“departments”)))
.exec(session => {
val departments = session(“departments”).as[Vector[Any]]
val depBuffer = departments(Random.nextInt(departments.length))
println(depBuffer)
session
})

`

So, this gets me my department but now I have to parse it :frowning:
I have tried specifying the type more than just Any but always get compiler issues. I can’t find a way to retrieve the value of ${departments.random()} . I can only use this inside a DSL function and none just return the value…

Could I get any direction in getting my ids? :slight_smile:

I didn’t fully understand what .findAll was doing I guess and so was casting to wrong types.

`

.check(status.is(200), jsonPath("$[*]").ofType[Map[String,Any]].findAll.saveAs(“departments”)))
.exec(session => {
val departments = session(“departments”).as[Vector[Map[String, Any]]]
println(departments(0).get(“details”))

`

This finally works and now I just need to understand how to cast Some, but that seems to be very Scala specific.