I am trying to export a json to file using html and js.
This is my code:
<form onsubmit="return make_json(this);">
name: <input type="text" name="first"/><br>
<input type="submit" value="JSON"/>
</form>
<pre id="output">
your json here
</pre>
<script>
function make_json(form) {
var json={
"first": form.first.value
};
var str = JSON.stringify(json, 0, 4);
document.getElementById('output').innerHTML = str;
return false;
}
</script>
As you can see, I displayed that json to the main page in html, but I have no idea how to export it to a file. I searched for an answer for a long time, but nothing helped me or mostly I couldn't understand the answer. Can anybody clarify this to me?