It\'s probably a very easy question but I\'m having trouble finding a clean/working solution. I just want to remove a field from a json object I have. Let\'s say I have :
You can use as Method as[JsObject]
with minus -
symbol. Like Below.
body.as[JsObject] - "id"
Below has detailed explanation step by step. Let's see with custom object.
val json: JsValue = JsObject(Seq(
"error" -> JsBoolean(false),
"result" -> JsNumber(calcResult),
"message" -> JsString(null)
))
It can be picked by as
Method and removed "-" symbol.
/* Removing Message Property and keep the value in successResult Variable */
val successResult = json.as[JsObject] - "message"
Take a look at Body Parser in Scala to know about Choosing an explicit body parser, Combining body parsers and Writing a custom body parser.