Klue Klue - 2 months ago 11
Scala Question

Convert JsDefined to String

I use play json library to process json objects in Scala. In order to get a field

id
from the json object, I run this code:

val id = json \ "id"


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


How to convert it into a String?

Answer

Try

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