Skip to content

Instantly share code, notes, and snippets.

@justinmoon
Created June 16, 2015 21:05
Show Gist options
  • Save justinmoon/58b9a8f3749c4d6f9b31 to your computer and use it in GitHub Desktop.
Save justinmoon/58b9a8f3749c4d6f9b31 to your computer and use it in GitHub Desktop.
Jinja2 filter: collapse nested dictionary into HTML table
{% 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