Download Object As Formatted JSON File
<p>I followed <a href="https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser">this guide</a> to download a JSON object from the browser. This is what my code looks like:</p>
<pre class="lang-js prettyprint-override"><code>var json = this.getEditorJSON();

var data = &quot;text/json;charset=utf-8,&quot; + encodeURIComponent(JSON.stringify(json));
var a = document.createElement('a');
a.href = 'data:' + data;
a.download = 'resume.json';
a.innerHTML = 'download JSON';

var container = document.getElementById('container');
container.appendChild(a);
a.click();

a.remove();
</code></pre>
<p>But this gives me a single line file that is hard to read. Is there an easy way to format it as a readable JSON file, with newlines and indentation?</p>