Liquid JSON template library

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.

Usage

```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); ```

Features

The serde feature (enabled by default) exposes 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;

[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]

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();

```

Additional Filters

This library extends the default Liquid filters with the following:

Example

Those filters can combine to produce complex JSON structures from simple input data. E.g.:

The input data:

json { "to": ["john@example.com", "jane@example.com"] }

Applied to the liquid JSON template:

json { "recipients" : "{{ to | each: '{ \"email\": \"{{ el }}\" }' | json | output }}" }

Produces the JSON:

json { "recipients": [ { "email": "john@example.com" }, { "email": "jane@example.com" } ] }