Skip to content

Instantly share code, notes, and snippets.

@riccardomerolla
Created March 30, 2014 17:14
Show Gist options
  • Save riccardomerolla/9876170 to your computer and use it in GitHub Desktop.
Save riccardomerolla/9876170 to your computer and use it in GitHub Desktop.
scala-json-getValue
val jsonString = """{"count":100205,"_shards":{"total":5,"successful":5,"failed":0}}"""
val tweets = scala.util.parsing.json.JSON.parseFull(jsonString)
def getValue(parsedJson: Option[Any], key: String): Double = {
parsedJson match {
case Some(m: Map[String, Any]) => m(key) match {
case d: Double => d
}
}
}
getValue(tweets, "count")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment