parseFull
will return an Option[Any]
which contains either a List[Any]
if the JSON string specifies an array, or a Map[String,Any]
if the JSON string specifies an object, as the documentation states.
In your case, the value you want to retrieve is a key-value pair in a map which is itself a key-value pair of the global map.
It is a bit ugly, but since you know the structure of your JSON, a combination of get
with asInstanceOf
, will permit you to get the typed value you want.
val jsonObject = JSON.parseFull("...")
val globalMap = x.get.asInstanceOf[Map[String, Any]]
val reviewMap = globalMap.get("reviewDetails").get.asInstanceOf[Map[String, Any]]
val reviewScore = reviewMap.get("review_score").get.asInstanceOf[Double]
Note that here I use get
"safely" because the value is known to exist in your context, but you can also use isEmpty
and getOrElse
.
If you want a scalable code, you can effectively look at How to parse JSON in Scala using standard Scala classes?