How to replace a JSON value in Play
问题 How do I replace a value in a JSON value in Play? Code to illustrate: def newReport() = Action(parse.json) { request => var json = request.body if((json \ "customerId").as[Int] == -1){ // replace customerId after some logic to find the new value } json.validate[Report](Reports.readsWithoutUser).map { case _: Report => 回答1: According to the Play Documentation, JsObjects have a method ++ that will merge two JsObjects. So, when you have your new integer value, you simply need: val updatedJson =