Created
November 9, 2014 15:17
-
-
Save ashrafuzzaman/2db9cec9fe3a209b4bc5 to your computer and use it in GitHub Desktop.
Scala parse JSON and access data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.parsing.json.JSON | |
val txt = """ | |
{ | |
"name" : "Watership Down", | |
"location" : { | |
"lat" : 51.235685, | |
"long" : -1.309197 | |
}, | |
"residents" : [ { | |
"name" : "Fiver", | |
"age" : 4, | |
"role" : null | |
}, { | |
"name" : "Bigwig", | |
"age" : 6, | |
"role" : "Owsla" | |
} ] | |
} | |
""" | |
val json = JSON.parseFull(txt) | |
val map = json.get.asInstanceOf[Map[String,Any]] | |
map.get("name").get.toString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool