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.
In your case, you have an "elif" so using "else empty" is probably what you want, but for reference, the above is exactly equivalent to:
select(CONDITION) | WHATEVER
P.S. My guess is that whatever the goal of the sed command, it could be done more reliably as part of the jq program, perhaps using walk/1
.
UPDATE
After the release of jq 1.6, a change was made so that "if without else" has the semantics of "if _ then _ else . end", that is:
if P then Q end
=== if P then Q else . end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…