Tutorial by Examples

You can build a JSON object tree (a JsValue) manually import play.api.libs.json._ val json = JsObject(Map( "name" -> JsString("Jsony McJsonface"), "age" -> JsNumber(18), "hobbies" -> JsArray(Seq( JsString("Fishing"), ...
public Result sayHello() { JsonNode json = request().body().asJson(); if(json == null) { return badRequest("Expecting Json data"); } else { String name = json.findPath("name").textValue(); if(name == null) { return badRequest...
@BodyParser.Of(BodyParser.Json.class) public Result sayHello() { JsonNode json = request().body().asJson(); String name = json.findPath("name").textValue(); if(name == null) { return badRequest("Missing parameter [name]"); } else { return ok...
If you are given a JSON string : val str = """{ | "name" : "Jsony McJsonface", | "age" : 18, | "hobbies" : [ "Fishing", "Hunting", "Camping" ], | "pet" : { | ...
Overall the easiest way to work with JSON is to have a case class mapping directly to the JSON (same fields name, equivalent types, etc.). case class Person( name: String, age: Int, hobbies: Seq[String], pet: Pet ) case class Pet( name: String, `type`: String ) // these...

Page 1 of 1