[2.3 Scala] easy way to convert List to json

1,845 views
Skip to first unread message

danny

unread,
Jun 4, 2014, 3:14:13 AM6/4/14
to play-fr...@googlegroups.com
Hi 

What this an easier way to convert a List to Json ?

Using 2.3 Scala 

Thanks
Paul


ido

unread,
Jun 4, 2014, 9:52:16 AM6/4/14
to play-fr...@googlegroups.com
A list of what?
If you have case classes in the list you only have to declare formatters.

some imports: maybe not all of them are necessary:
import play.api.libs.json.Json
import play.api.libs.json.Json._
import play.api.libs.json.Format
import play.api.libs.json.JsSuccess
import play.api.libs.json.Writes

case class Mything(name: String, number: Int)
implict val f = Json.format[Mything]

val items = Seq(Mything("a",1),Mything("b",2))

Ok(Json.toJson(items)

HTH and it compiles,
ido

TheLovealien .

unread,
Jun 5, 2014, 2:42:22 AM6/5/14
to play-fr...@googlegroups.com
Thanks so much :)

The documents confuse me :( lol




--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages