title: Download JSON object as a file from browser
body: <p>I have the following code to let users download data strings in csv file.</p>
  
  <pre><code>exportData = 'data:text/csv;charset=utf-8,';
  exportData += 'some csv strings';
  encodedUri = encodeURI(exportData);
  newWindow = window.open(encodedUri);
  </code></pre>
  
  <p>It works just fine that if client runs the code it generates blank page and starts downloading the data in csv file.</p>
  
  <p>So I tried to do this with JSON object like</p>
  
  <pre><code>exportData = 'data:text/json;charset=utf-8,';
  exportData += escape(JSON.stringify(jsonObject));
  encodedUri = encodeURI(exportData);
  newWindow = window.open(encodedUri);
  </code></pre>
  
  <p>But I see only a page with the JSON data displayed on it, not downloading it.</p>
  
  <p>I went through some research and <a href="https://stackoverflow.com/questions/8080929/how-to-save-a-file-at-client-side-using-javascript">this one</a> claims to work but I don't see any difference to my code.</p>
  
  <p>Am I missing something in my code?</p>
  
  <p>Thanks for reading my question:)</p>