title: Handling JSON requests in Play Framework 2.0 Scala
body: <p>I am trying to send data from the client to the server using a JSON request. The body of the JSON request looks like this:</p>
  
  <pre><code>{
  "upload":
      {
      "ok":"some message",
      "assemblyId":"a9d8f72q3hrq982hf98q3"
      }
  }
  </code></pre>
  
  <p>Play is able to recognize the request body as JSON but when I try to parse individual values, namely the "upload" object, Play complains that it can't find the specified parameter.</p>
  
  <p>The Scala method is as follows:</p>
  
  <pre><code>def add(course:Long) = withAccount { account =&gt; implicit request =&gt;
    println()
    println(request.body)  // output: AnyContentAsJson({"upload":{"ok":"ASSEMBLY_COMP...
  
    request.body.asJson.map { json =&gt;
      println()
      println(json)  // output: {"upload":{"ok":"ASSEMBLY_COMPLETED","assemb...
  
      (json \ "upload").asOpt[models.SomeClass].map { upload =&gt;
        Ok("Got upload")
      }.getOrElse {
        BadRequest("Missing parameter [upload]")
      }
    }.getOrElse {
      BadRequest("Expecting Json data")
    }
  }
  </code></pre>
  
  <p>I'm having trouble understanding why the above code fails. The method has no trouble mapping the request body to a json object. The "println(json)" command prints out the exact same thing that Chrome shows me as the 'Request Payload'. Yet, when I try to grab the root object, "upload", it fails. And the method returns a bad request complaining about the missing parameter.</p>