[][src]Function jsonlogic::apply

pub fn apply(json_logic: &Value, data: &Value) -> Result<Value, String>

Applies the given JsonLogic rule to the specified data. If the rule does not use any variables, you may pass &Value::Null as the second argument.

Example

use serde_json::{json, Value};

let rule = json!({
    "===": [
        2,
        { "var": "foo" }
    ]
});

let data = json!({ "foo": 2 });
assert_eq!(jsonlogic::apply(&rule, &data), Ok(Value::Bool(true)));

let data = json!({ "foo": 3 });
assert_eq!(jsonlogic::apply(&rule, &data), Ok(Value::Bool(false)));