[][src]Function balena_temen::evaluate

pub fn evaluate(data: Value) -> Result<Value>

Evaluates the whole JSON

Arguments

  • data - A JSON to evaluate

Examples

An object evaluation.

use balena_temen::{evaluate, Value};
use serde_json::json;

let data = json!({
  "$$eval": "1 + 2"
});

assert_eq!(evaluate(data).unwrap(), json!(3));

Chained dependencies evaluation.

use balena_temen::{evaluate, Value};
use serde_json::json;

let data = json!({
    "ssid": "Zrzka 5G",
    "id": {
        "$$eval": "super.ssid | slugify"
    },
    "upperId": {
        "$$eval": "super.id | upper"
    }
});

let evaluated = json!({
    "ssid": "Zrzka 5G",
    "id": "zrzka-5g",
    "upperId": "ZRZKA-5G"
});

assert_eq!(evaluate(data).unwrap(), evaluated);