Pretty Print Raw MiniJinja JSON Data On A Template
July 2023
I use MiniJinjamj to create the templates for my site. The output data comes in from Serdese in a JSON like syntax. I use this snippet to pretty print it so it's easier to work with:
TODO
☐
this is new code to look at:
<input type="hidden" id="neo_string" value="{% autoescape true %}{{ page.all_sections() }}{% endautoescape %}" />
<pre id="neo_formatted"></pre>
<script>
const updateIt = => {
neo_formatted.innerText = JSON.stringify
}
document.addEventListener
</script>Notes
-
This goes in a template that receives data in a
pagecontext variable -
The data is placed in a hidden input element to start with then scrubbed and output in the
pretag when the page is loaded -
I have optional values that come across in the origial data as
Nonewithout quotes. The script adds the qutoes to diminish parsing issues
end of line