Harinya
Harinya

Reputation: 191

parse Json String using scala.util.parsing.json

I have a json string and I wast to be able to parse it to get the 'key' values.

jsonString = {"id":2279,
"name":"Test",
"description":null,
"tags":[],
"keys":[{
"key":"WI1MX6XAWSY03X8Y",
"flag":true},
{"key":"BK2Q18T8RSN6VODR",
"flag":false}]}

I want to be able to parse this string and get values for both the keys.

Currently I'm doing:

val details = JSON.parseFull(jsonString)
val keys = details.get.asInstanceOf[Map[String, Any]]("keys")
println(keys)

keys here is:

List(Map(key -> 3JP11GJ5OOGOVV5N, flag -> true), Map(key -> F49M347FOHYKBT9, flag -> false))

Please let me know how i can get both the 'key' values.

Upvotes: 3

Views: 3058

Answers (1)

Simon
Simon

Reputation: 6452

There is nothing related to JSON actually, you just have to do:

val keysValues = key.map(k => k("key"))

Upvotes: 1

Related Questions