Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a key from a JsValue in Scala

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 :

val body:Option[JsValue] = request.body.asJson

where body looks like:

{
     "url": "www.google.com",
     "id":  "123",
     "count" : 1,
     "label" : "test"  
 }

and I want to remove the field "id" from it.

I have read http://www.playframework.com/documentation/2.1.1/ScalaJsonTransformers case#6 but unfortunately couldn't fully understand it. (I'm pretty new to Scala and functional programming)

Thanks!

like image 830
N3da Avatar asked Jul 31 '14 18:07

N3da


1 Answers

This can be done as a JsObject, which extends JsValue:

body.as[JsObject] - "id"
like image 177
Michael Zajac Avatar answered Oct 01 '22 01:10

Michael Zajac