0

I have an object like this:

val aa = parse(""" { "vals" : [[1,2,3,4], [4,5,6,7], [8,9,6,3]] } """)

I want to access the value '1' in the first JArray.

println(aa.values ???)

How is this done?

Thanks

nietsnegttiw
  • 371
  • 1
  • 5
  • 16

1 Answers1

3

One way would be :

val n = (aa \ "vals")(0)(0).extract[Int]
println(n)

Another way is to parse the whole json using a case class :

implicit val formats = DefaultFormats

case class Numbers(vals: List[List[Int]])

val numbers = aa.extract[Numbers]

This way you can access the first value of the first list however you like :

for { list <- numbers.vals.headOption; hd <- list.headOption } println(hd)
// or
println(numbers.vals.head.head)
// or ...
Peter Neyens
  • 9,770
  • 27
  • 33