Let's say I have this little Argonaut Json
instance:
import argonaut._, Argonaut._
Json.obj(
"id" := 42,
"viewed" := false
)
Now, I want to remove the pair whose key is viewed
. I found the following to work, but it's a bit too verbose. Is there anything shorter than this:
for {
field <- json.cursor.downField("viewed")
updated <- field.delete
} yield updated.undo
Also, the name of the method that "commits" the changes (undo
) seems a bit misleading in my opinion? How should I interpret the name? Initially I thought there's a way to undo the last change in the history of modifications.
UPDATE
I have found one solution. Using an HCursor
:
json.hcursor.downField("viewed").delete.undo
The question of why undo
is named undo
is still open though.