You can use the idiom:
if CONDITION then WHATEVER else empty end
empty is a filter that displays nothing at all - even zero, which, after all, is something (namely, the JSON value). This is a bit like a black hole, only blacker - it will absorb everything that it has proposed, but unlike a black hole, it does not even emit Hawking radiation.
In your case, you have "elif", so using "else empty" is probably what you need, but for reference, the above is exactly equivalent:
select(CONDITION) | WHATEVER
PS I assume that whatever the purpose of the sed command is, it can be done more reliably as part of the jq program, possibly using walk/1 .
UPDATE
After the release of jq 1.6, a change was made, so that "if without the other" has the semantics of "if _, then _ else. End", that is:
if P then Q end === if P then Q else. end if P then Q else. end if P then Q else. end if P then Q else. end
source share