Expressions
Conditions, set_variable values and terminal outputs are all expressions. The language is small: no loops, no assignments, no side effects.
You can try any expression with the CLI:
bash
ordo eval 'order.amount >= 1000 && user.tier == "gold"' \
--input '{"order":{"amount":1200},"user":{"tier":"gold"}}'Values
| Kind | Examples |
|---|---|
| Number | 42, 3.14 |
| String | "gold", 'gold' |
| Boolean | true, false |
| Null | null |
| Array | [1, 2, 3], ["a", "b"] |
| Object | {"a": 1} |
Fields and variables
user.name # a field of the input
order.items.0.price # array element by index
$subtotal # a variable set by an earlier step
$data.limits.vip_min # external data loaded by the server or `ordo exec --data`A missing field makes its own comparison false by default, and the rest of the condition still counts: age < 18 || blacklisted is true for a blacklisted applicant who sent no age. To reject such input instead, declare an input schema or set field_missing: strict.
Operators
| Operator | Meaning |
|---|---|
+ - * / % | Arithmetic. + also joins strings |
== != < <= > >= | Comparison |
&& or and, || or or | Logic |
! or not | Negation |
x in [..], x not in [..] | Membership |
s contains "sub", arr contains x | Substring or array item |
age >= 18 && status == "active"
tier in ["gold", "platinum"]
email contains "@example.com"Binding, from loosest to tightest: ||, &&, comparisons, in / not in / contains, + -, * / %. Use parentheses when in doubt.
Numbers
- Numbers compare by value:
3 == 3.0is true. - Division does not truncate:
10 / 4is2.5,10 / 5is2. Usefloor(a / b)for integer division. - Strings and numbers are not converted for you:
"100" > 50is an error. Useto_int(...)orto_float(...). - For money, use
decimal(...)or declare the field asdecimalin the input schema.decimal(0.1) + 0.2 == 0.3is true. Arithmetic with a decimal stays decimal.
Strings
\n, \t, \r, \\, \" and \' are escapes. Any other backslash is kept, so a regex reads as written: regex_match("^\d+\.\d{2}$", s).
Conditionals
if tier == "gold" then 0.20 else if tier == "silver" then 0.10 else 0.05Missing values
exists(user.discount) # true if the field is there and not null
coalesce(user.nickname, user.name, "Guest") # first value that is not nullFunctions
len(items) > 0
round(price * 0.85, 2)
starts_with(order_id, "ORD-")See Built-in Functions for the full list.