Created
June 16, 2015 21:05
-
-
Save justinmoon/58b9a8f3749c4d6f9b31 to your computer and use it in GitHub Desktop.
Jinja2 filter: collapse nested dictionary into HTML table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro render_nested(json, key) -%} | |
<table> | |
{% if json.get(key) %} | |
{% for key, value in json.get(key).items() recursive %} | |
{% if value is mapping %} | |
{{ loop(value.items()) }} | |
{% else %} | |
<tr> | |
<td>{{ key }}</td> | |
<td>{{ value }}</td> | |
</tr> | |
{% endif %} | |
{% endfor %} | |
{% else %} | |
<p>None</p> | |
{% endif %} | |
</table> | |
{%- endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment