Skip to content

Instantly share code, notes, and snippets.

@hvgab
Created January 26, 2018 16:24
Show Gist options
  • Save hvgab/050e4e33f16c8b8939d02f39aa0ca164 to your computer and use it in GitHub Desktop.
Save hvgab/050e4e33f16c8b8939d02f39aa0ca164 to your computer and use it in GitHub Desktop.
Add a json prettyprint filter for jinja
# prettyprint json i jinja
def ppjson(value, indent=2):
return json.dumps(value, indent=indent)
jinja2.filters.FILTERS['ppjson'] = ppjson
@Bierchermuesli
Copy link

there is also a built-in one: {{ foo | tojson(2) }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment