Closed elmaimbo closed 2 months ago
Hello, agreed! have a look at https://github.com/jqlang/jq/issues/2042 discussion this
I also want this, best proposed syntax currently is ///
.
??
probably is not a good option because it may be confused with the ?
operator:
foo?? - bar
That currently means:
(try (try foo catch empty) catch empty) - (bar)
Will become
(foo) ?? (-(bar))
But, at the same time, it doesn't make much sense to use the ?
two times in a row.
Anyway, closing as duplicate
@elmaimbo if you want to experiment see this comment https://github.com/jqlang/jq/issues/2042#issuecomment-2082697844
I feel that the way the alternative operator
//
handles the valuefalse
is problematic, given that 'falsey' values of other types (such as the number0
or the empty string""
) aren't treated in the same way.The
//
documentation mentions:However if you adapt this example to
.foo // true
then you'll end up withtrue
in the case where the.foo
has the valuefalse
in the input. The solution is rather clumsy:if .foo == null then true else .foo end
I feel that a 'nullish coalescing operator', similar to the
??
operator used in JavaScript, would be far more useful. And since changing the behaviour of//
has the potential to create problems for existing scripts, I'd like to request the addition of the??
infix operator for JQ, which has the same semantics as//
except thatfalse
is treated the same as any other (non-null) value?To paraphrase the
//
documentation:Thanks.