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::new(templatejson); let actual = tmpl.render(template_data)?;
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
struct YourStruct { inner_liquid: LiquidJsonValue, }
let jsondata = json!({"innerliquid":"{{myval}}"});
let template_data = json!({"myval": 5});
let yours: YourStruct = serdejson::fromvalue(fromjson.clone())?; let actual = yours.innerliquid.render(data)?;
```