Skip to content

Instantly share code, notes, and snippets.

@mandubian
Created February 18, 2012 13:57
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 mandubian/1859395 to your computer and use it in GitHub Desktop.
Save mandubian/1859395 to your computer and use it in GitHub Desktop.
enriched json for play2
object Application extends Controller {
def index = Action {
import RichJson._
// Classic Play20 JSon API
val oldVersion =
JsObject(Seq(
("key1", JsObject(Seq(
("key11", JsString("alpha11")),
("key12", JsString("alpha12"))
))
),
("key2", JsObject(Seq(
("key21", JsNumber(23)),
("key22", JsBoolean(true))
))
),
("key3", JsObject(Seq(
("key31", JsArray(List(
JsString("key311"),
JsNumber(67.23),
JsString("key313"),
JsObject(Seq(
("key311", JsString("alpha311")),
("key312", JsString("alpha312"))
))
))
)
))
)
))
// with rich Json API
val newVersion =
"key1" \: (
"key11" \: "alpha11" ++
"key12" \: "alpha12"
) ++
"key2" \: (
"key21" \: 23 ++
"key22" \: true
) ++
"key3" \: (
"key31" \: (
"key311" @@
67.23 @@
"key313" @@
( "key311" \: "alpha311" ++
"key312" \: "alpha312" ) )
)
assert(newVersion == oldVersion, "Not equal")
Ok(toJson(newVersion))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment