-
Notifications
You must be signed in to change notification settings - Fork 254
Closed
Labels
Description
This is a proposal for a new function:
$error(message)
It behaves like XPath's fn:error. Calling $error from an expression causes it to abort with the specified error message. This is useful for validating input data. If, for example, you require certain fields to be present in your JSON, you can check for them upfront and throw a meaningful error if they don't exist.
(
$assert := function($cond, $msg) {
$not($cond) ? $error($msg)
};
$assert(some.value % 2 = 0, "value must be an even number");
$assert($length(some.other.value) = 3, "value must be a 3 letter acronym");
$assert(another.value != null, "value cannot be null");
<-- main expression goes here -->
)
jhorbulyk