Skip to content

Instantly share code, notes, and snippets.

@kouphax
Created March 9, 2014 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kouphax/9450253 to your computer and use it in GitHub Desktop.
Save kouphax/9450253 to your computer and use it in GitHub Desktop.
Some JSON magic in Play.
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.json._
import play.api.libs.functional.syntax._
object Application extends Controller {
implicit val jsonifier = (
(__ \ "id").format[Int] and
(__ \ "name").format[String]
)(Shannon.apply, unlift(Shannon.unapply))
case class Shannon(val id: Int, val name: String)
def index = Action {
val json = """[{"id":1,"name":"james"},{"id":2,"name":"shannon"}]"""
val list = Json.fromJson[List[Shannon]](Json.parse(json))
Ok(Json.toJson(list.get))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment