I currently just show the JSON in my template with
<pre>{{ mydata | json }}</pre>
I like to add a button for users to download the json data. Is there an easy way to do this ?
Downloading the JSON data, means downloading a file containing a JSON string.
If you are already able to render that file on the server, then you just need to create an html link, with the href
attribute pointing to the corresponding server url.
In order to force the file to be downloaded, you have to declared it as an attachment in an http header. The response must contains something like this:
'Content-Disposition: attachment; filename=data.json'
You can also specify the content-type with another response header:
'Content-Type': application/json
Edit: I just discovered that apparently you can initialize a file download directly from the client. See this SO topic. Seems to be pretty well supported: http://caniuse.com/#feat=bloburls