Skip to content

Instantly share code, notes, and snippets.

@ashrafuzzaman
Created November 9, 2014 15:17
Show Gist options
  • Save ashrafuzzaman/2db9cec9fe3a209b4bc5 to your computer and use it in GitHub Desktop.
Save ashrafuzzaman/2db9cec9fe3a209b4bc5 to your computer and use it in GitHub Desktop.
Scala parse JSON and access data
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
@twilightgod
Copy link

Cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment