Convert JsDefined to String

I am using json library to handle json objects in Scala. To get the id field from a json object, I run this code:

val id = json \ "id"

Then I want to convert id to string. I tried id.get.toString , but instead of doi:10.1186-s13612-016-0045-3 got JsDefined("doi:10.1186-s13612-016-0045-3")

How to convert it to string?

+6
source share
2 answers

Try

 (json \ "id").as[JsString].value 
+4
source

Slightly shorter:

 (json \ "id").as[String] 
+5
source

All Articles