Reputation: 529
Input:
{
"name":"JSON",
"good":true,
"target":"yes"
}
{
"name":"XML",
"good":false
}
I would like to exclude object WITHOUT key "target", as follow but NOT has:
jq -r ".| select(has(\"target\"))"
expected output:
{
"name":"XML",
"good":false
}
tried this:
jq -r " . | del(select(has(\"target\")))"
but there are two returned objects, one of them NULL
null
{
"good": false,
"name": "XML"
}
Upvotes: 6
Views: 6893
Reputation:
Select those who do not have target
; that way, you do not use del
:
jq -r 'select(has("target") | not)'
Upvotes: 11