/// Renders a template using variables from `serde_json::Value`
///
/// The value must be JSON object or error is returned
Renders a template using variables from `serde_json::Value`
The value must be JSON object or error is returned
Renders a template using variables from ` serde_json :: Value ` The value must be JSON object or error is returned
pub fn render_json(tpl: &Template, json: &Value) -> Result<String, RenderError>
{
    match json.as_object() {
        Some(map) => {
            let mut ctx = Context::new();
            for (k, v) in map {
                ctx.set(k, v);
            }
            tpl.render(&ctx)
        }
        None => {
            Err(RenderError::Data(vec![
                (Pos { line: 0, column: 0 },
                 DataError::Custom("render_json expects a JSON object".into()))
            ]))
        }
    }
}
pub fn render_json ( tpl : & Template , json : & Value ) -> Result < String , RenderError > { match json . as_object ( ) { Some ( map ) => { let mut ctx = Context :: new ( ) ; for ( k , v ) in map { ctx . set ( k , v ) ; } tpl . render ( & ctx ) } None => { Err ( RenderError :: Data ( vec ! [ ( Pos { line 0 column 0 } DataError Custom ( " " into ( ) ) ) ] ) ) } } }
Renders a template using variables from `serde_json::Value`
The value must be JSON object or error is returned
Renders a template using variables from ` serde_json :: Value ` The value must be JSON object or error is returned
tpl
&Template
json
&Value