# Retrieving json data two arrays deep

**URL:** <https://community.gatling.io/t/retrieving-json-data-two-arrays-deep/2640>\
**Category:** Gatling (Open-Source)\
**Created:** [October 27, 2015, 1:53am UTC](https://community.gatling.io/t/retrieving-json-data-two-arrays-deep/2640 "2015-10-27T01:53:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lois\_Desplat](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@Lois\_Desplat](https://community.gatling.io/u/Lois_Desplat)\
**Post date:** [October 27, 2015, 1:53am UTC](https://community.gatling.io/t/retrieving-json-data-two-arrays-deep/2640/1 "2015-10-27T01:53:07Z")

</div>

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 ☹  
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? 🙂

---

<div class="post-metadata">

**Author:** ![Lois\_Desplat](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@Lois\_Desplat](https://community.gatling.io/u/Lois_Desplat)\
**Post date:** [October 27, 2015, 3:01am UTC](https://community.gatling.io/t/retrieving-json-data-two-arrays-deep/2640/2 "2015-10-27T03:01:14Z")

</div>

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.
