I use the following JQ command to filter out the JSON. My requirement is to filter out the JSON message if the expected node is present. Or else, do nothing. Hence, I use if, elif, ....
sed -n "s/.*Service - //p" $1/response.log* |
jq "if (.requests | length) != 0 then .requests |= map(select(.id == \"123\"))
elif (.result | length ) != 0 then .result |= map(select(.id== \"123\"))
else " " end" > ~/result.log
You may want to use the idiom:
if CONDITION then WHATEVER else empty end
empty is a filter that outputs nothing at all -- not even null, which is after all something (namely a JSON value). It's a bit like a black hole, only blacker -- it will consume whatever it's offered, but unlike a black hole, it does not even emit Hawking radiation.