Language Enhancements
In addition to the Jsonnet language, DataSonnet includes the following language enhancements:
-
try/else
statement. If the expression aftertry
results in error, the expression afterelse
will be evaluated. For example:
{ tryNonexistent: try payload.doesntExist else "OK", tryChain: try payload.doesntExist else try payload.missing else "OK", tryNaN: try std.parseInt("NotANumber") else -1, tryInIf: if (try payload.doesntExist else "OK") == "OK" then "OK" else "NotOK" }
-
default
operator - this is a syntax sugar fortry/else
. For example:
{ tryNonexistent: payload.doesntExist default "OK", tryChain: payload.doesntExist default payload.missing default "OK", tryNaN: std.parseInt("NotANumber") default -1 }
See Also: default
header