safe_not_null

Return the result of first expression that doesn't resolve to null

Definition

any safe_not_null(any $input, expression->any *$expressions)

Evaluates a series of one or more expressions against $input and returns the first non-null result. If all the expressions evaluate to null, returns null.

Parameters

any $input

Input data to evaluate the expressions on.

expression->any *$expressions

Expressions to evaluate the input data.

Returns

any

The result of the first expression that returns a non-null result, or null if all of them return null.

Examples

{
  a: safe_not_null(`null`, @, @.a, !@, has_value(@)),
  b: safe_not_null(`{}`, @.a, safe_mode(avg(@)), length(@))
}
{
  "a": true,
  "b": 0
}