JSON PATCH / Remove: how to remove specific value from an object?

Viewed 919

How do you remove a value from an object in an http patch request?

For example:

{
  "types": [
    {
      "id": 12,
      "name": "xyz",
    },
    {
      "id": 13,
      "name": "ABC",
    }
  ]
}

How do you remove where type/id=13?

Is it like this?

[{
    "op":"remove",
    "path":"types/13"
}]

Or like this?

[{
    "op":"remove",
    "path":"types",
    "value":[{"id":13}]
}]

Also, Im not looking the delete the position no2 solution!

Thanks :)

1 Answers

One solution I found by the 3rd party I was using was to "update" with "null" and that deletes the specific entry. (Im not sure if it works universally)

[{
    "op":"replace",
    "path":"types",
    "value":[{
        "id": 13,
        "value": null
    }]
}]
Related