Skip to main content

Module expr

Module expr 

Source
Expand description

Expression evaluation for node config values (the =-prefix convention).

A config string beginning with = is an expression. The remainder is a jq program, compiled and executed by jaq, with the entire evaluation scope as the jq input (.). For example, "=.item.name" yields scope["item"]["name"], and "=.item.items | length" yields the length of that array. Only the first output value of the program is returned.

As a backward-compatible shorthand, a remainder that is a simple dotted path — segments matching [A-Za-z_][A-Za-z0-9_]* joined by ., e.g. "=item.name" — is resolved by a direct segment-walk over the scope (Value::Null for a missing segment) instead of the jq engine, so legacy expressions keep their exact behavior.

Anything that is not a =-prefixed string is returned as a literal clone. jq programs never panic: a compile/run error, non-JSON output, or empty output all yield Value::Null.

Functions§

evaluate
Evaluates a config value against scope.
is_expression
Returns true if s is an expression (begins with =).
resolve
Recursively resolves every =-expression embedded anywhere in a config value, evaluating each against scope.