iferror
utilityReturns fallback if value causes an error
Syntax
iferror(value, fallback) Parameters
value (any) The expression to evaluate
fallback (any) Value returned if the expression errors
Returns
any Either the value or the fallback depending on whether an error occurs
Examples
Convert to number, use 0 if fails
Input:
iferror(.field | tonumber, 0) Output:
0 Parse JSON, use empty object if fails
Input:
.config | iferror(fromjson, {}) Output:
{} The iferror() function safely evaluates an expression and returns a fallback value if an error occurs.
Usage
Use iferror() to handle potential errors gracefully in data processing, such as failed type conversions or invalid operations.