title: Export json to json file
body: <p>I am trying to export a json to file using html and js.</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;form onsubmit="return make_json(this);"&gt;
      name: &lt;input type="text" name="first"/&gt;&lt;br&gt;
      &lt;input type="submit" value="JSON"/&gt;
  &lt;/form&gt;
  
  &lt;pre id="output"&gt;
      your json here
  &lt;/pre&gt;
  
  &lt;script&gt;
      function make_json(form) {
          var json={
              "first": form.first.value
          };
  
          var str = JSON.stringify(json, 0, 4);
          document.getElementById('output').innerHTML = str;
  
          return false;
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>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?</p>