That's not what del/1
was meant to be used for. Given an object as input, if you wanted to remove the .phones
property, you'd do:
del(.phones)
In other words, the parameter to del
is the path to the property you wish to remove.
If you wanted to use this, you would have to figure out all the paths to null
values and pass it in to this. That would be more of a hassle though.
Streaming the input in could make this task even simpler.
fromstream(tostream | select(length == 1 or .[1] != null))
Otherwise for a more straightforward approach, you'll have to walk through the object tree to find null
values. If found, filter it out. Using walk/1
, your filter could be applied recursively to exclude the null
values.
walk(
(objects | with_entries(select(.value != null)))
// (arrays | map(select(. != null)))
// values
)
So if you had this for input:
{
"foo": null,
"bar": "bar",
"biz": [1,2,3,4,null],
"baz": {
"a": 1,
"b": null,
"c": ["a","b","c","null",32,null]
}
}
This filter would yield:
{
"bar": "bar",
"baz": {
"a": 1,
"c": ["a","b","c","null",32]
},
"biz": [1,2,3,4]
}