You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the syntax for conditionals, requires an else case. If this were changed to allow only an if case and to not output a value if the case that doesn't match then the program which supplies the above could be:
./jq 'if .foo == "bar" then . end'
My current work around involves using the else case to output a sentinel value which I grep away before piping back into jq again.
The text was updated successfully, but these errors were encountered:
would do what you want. empty is a builtin that produces zero results. You can in theory implement it yourself with something like [][] (each element of an empty array).
I intentionally didn't implement if-without-else, since I'm not sure whether the best default for "else" behaviour is produce-no-output or dont-change-the-input (that is, whether the implicit else block should be . or empty). This sounds like a vote for empty.
Ah. Brilliant. I don't think there's any need for if-without-else in the presence of select and empty. Closing this ticket because there's no issue with jq, just a gap in the docs. Cheers.
I might well be reading the docs wrong, but I don't think there's a way to perform the following operation. Given the input
Get only the objects where
.foo == "bar"
, resulting in the output:Currently the syntax for conditionals, requires an else case. If this were changed to allow only an if case and to not output a value if the case that doesn't match then the program which supplies the above could be:
My current work around involves using the else case to output a sentinel value which I grep away before piping back into jq again.
The text was updated successfully, but these errors were encountered: