Skip to content

#try

Evaluates an expression, and if it fails, evaluates a lambda with the exception and returns that result instead.

#try(expression, @e: fallback)
Category Control flowValid in Property value
Name Type Description
expression any The expression to attempt.
fallback lambda Receives the error as @e (with message, exceptionType and, for errors raised by Jolt, a code such as JLT563) and returns the replacement value.

any

source.json
{
"stringValue": "not a number",
"defaultValue": 0
}
transformer.json
{
"result": "#try(#valueOf($.stringValue)->#toInteger(), @e: #valueOf($.defaultValue))"
}
output.json
{
"result": 0
}

Try it in the playground →

source.json
{
"name": "Jolt"
}
transformer.json
{
"result": "#try(#toUpperCase($.nickname), @e: #if(@e.code == 'JLT563', 'no nickname', 'invalid nickname'))"
}
output.json
{
"result": "no nickname"
}

Try it in the playground →

#toInteger