I want to remove sub elements from an array for example
{
"employees": [
{
"name": "name1",
"id": "id1"
},
{
"name": "name2",
"id": "id2"
},
{
"name": "name3",
"id": "id3"
}
]
}
And i need a patch to remove all ids so i can do something like this
[{ "op": "remove", "path": "/employees/0/id"},
{ "op": "remove", "path": "/employees/1/id"},
{ "op": "remove", "path": "/employees/2/id"}]
But is there any way to specify wildcard to select all id elements in an array
I've been looking at the JSON patch draft but didn't find anything about regular expressions. One solution is to use some
JSON
parse tools to create it, like jq and python-json-patch. The first one removes allid
keys, and the second one creates a patch from a diff, used like:It yields:
Using also the
jsonpatch
tool to apply the patch, it seems to generate a correct output, like:It yields: