Evaluate expression
eval_expressionEvaluate a single JSONata expression against a sample input document and return the computed value, or the exact compile/eval error. Write the expr exactly as in a derivation/constraint 'expr': bare dot-paths, no leading $ (e.g. "loan.amount * loan.annualRate / 1200"). Use this to verify an expression before putting it in a spec — it uses the same compiler the runtime validates against. If the expression calls a library function, pass the model's library definition as 'library' — without it every $myFn(...) call fails as undefined.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expr | Yes | A single JSONata expression (bare dot-paths, no leading $). | |
| input | No | Sample document the expression runs against (full nested shape, e.g. {"loan": {"amount": 20000}}). Optional; defaults to {}. | |
| library | No | Optional JSONata library definition expression whose exports are bound while evaluating, e.g. "( $money := function($n){ $round($n,2) }; [\"money\"] )". Pass it when the expression calls $myFn(...). | |
| constants | No | Optional constants bound as $const while evaluating (and while defining the library). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | No | True when the expression compiled and evaluated. | |
| error | No | 'compile' or 'evaluation' when ok is false. | |
| message | No | The compile/eval error message when ok is false. | |
| undefined | No | True when the result is JSONata 'undefined' (no match). |