pub fn json_pretty(
value: impl Serialize,
indent: impl AsIndent,
) -> Result<impl Display, Infallible>Expand description
Serialize to formatted/prettified JSON (requires json feature)
This filter works the same as json(), but it formats the data for human readability.
It has an additional “indent” argument, which can either be an integer how many spaces to use
for indentation (capped to 16 characters), or a string (e.g. "\u{A0}\u{A0}" for two
non-breaking spaces).
§Note
In askama’s template language, this filter is called |json, too. The right function is
automatically selected depending on whether an indent argument was provided or not.
/// ```jinja
/// <div>{{data|json(4)|safe}}</div>
/// ```
#[derive(Template)]
#[template(ext = "html", in_doc = true)]
struct Example<'a> {
data: Vec<&'a str>,
}
assert_eq!(
Example { data: vec!["foo", "bar"] }.to_string(),
"<div>[
\"foo\",
\"bar\"
]</div>"
);