pub fn evaluate(value: &Value, scope: &Value) -> ValueExpand description
Evaluates a config value against scope.
A string like "=item.name" (a simple dotted path) resolves that path
within scope, with missing segments yielding Value::Null. Any other
=-prefixed string is treated as a jq program run against scope (see
the module docs), returning its first output or Value::Null.
Non-expression values are returned as a literal clone.
ยงExamples
use serde_json::json;
use tinyflows::expr::evaluate;
let scope = json!({ "user": { "name": "Ada" }, "nums": [1, 2, 3] });
// A simple dotted path walks the scope segment by segment.
assert_eq!(evaluate(&json!("=user.name"), &scope), json!("Ada"));
// A leading dot routes to the jq engine; here, the array length.
assert_eq!(evaluate(&json!("=.nums | length"), &scope), json!(3));
// A missing path yields null rather than erroring.
assert_eq!(evaluate(&json!("=user.email"), &scope), json!(null));
// Non-expression values pass through as a literal clone.
assert_eq!(evaluate(&json!("literal"), &scope), json!("literal"));
assert_eq!(evaluate(&json!(42), &scope), json!(42));