Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 327
Klue Avatar asked Jul 10 '16 17:07

Klue


2 Answers

Slightly shorter:

(json \ "id").as[String]
like image 103
Bryant Kou Avatar answered Nov 16 '22 04:11

Bryant Kou


Try

(json \ "id").as[JsString].value
like image 22
slouc Avatar answered Nov 16 '22 05:11

slouc