Save json file

by Max Sinev

JavaScript

var json =  JSON.stringify({ foo: 'bar' }),
name = 'some-json-file.json';

var blob = new Blob([json], { type: 'text/json' });

// for ie
if (window.navigator.msSaveBlob) {
  window.navigator.msSaveBlob(blob, name);

} else {
  var event = new MouseEvent('click'),
      a = document.createElement('a');
  a.download = name;
  a.href = window.URL.createObjectURL(blob);
  a.dispatchEvent(event);
}