jq Joy: Using Default Values With The Alternative Operator
jq
is a powerful tool to work with JSON from the command-line. The tool has a lot of functions and operators that makes our live easier. One of the operators we can use is the alternative operator //
which allows us to specify default values. If the value on the left side of the operator //
is empty, null or false then the value on the right side is returned, otherwise the value itself is returned. The operator can be used multiple times if we want to have multiple fallbacks for a value we are checking.