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 :
I came across this question when I wanted to remove a nested field from a json object, and since subtracting doesn't work for nested fields, I'm adding the solution I ended up using.
To remove a field from a JsObject you can use prune to remove the entire path to that field.
For the example above -
val p = JsPath \ "id"
val res = p.prune(body.as[JsObject]).get
If you had a nested object like this -
{
"url": "www.google.com",
"id": {"first": "123", "second": "456"}
"count" : 1,
"label" : "test"
}
you could create a more specific path -
val p = JsPath \ "id" \ "second"
val res = p.prune(body.as[JsObject]).get