This library is a small wrapper around the Liquid templating engine that recursively processes structured JSON values for Liquid templates.
Liquid JSON templates help templatize JSON files used in configuration or RPC transmission.
```rust use serdejson::json; let templatejson = json!({"this":"{{myval}}"}); let templatedata = json!({"myval": 5}); let tmpl = liquidjson::LiquidJson::new(templatejson); let actual = tmpl.render(&templatedata).unwrap();
let expected = json!({"this": 5}); // {{myval}} is replaced with 5 assert_eq!(actual, expected); ```
Turn on the serde
feature to expose LiquidJsonValue
. LiquidJsonValue
is a wrapper around LiquidJson
(and serde_json::Value
) that lets you embed LiquidJson
templates in your structs, e.g.
```rust use serde_json::json;
struct YourStruct { innerliquid: liquidjson::LiquidJsonValue, }
let jsondata = json!({"innerliquid":"{{myval}}"});
let template_data = json!({"myval": 5});
let yours: YourStruct = serdejson::fromvalue(jsondata).unwrap(); let actual = yours.innerliquid.render(&template_data).unwrap();
```