var json = localStorage.getItem('theData'); var blob = new Blob([json], {type: "application/json"}); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.download = "backup.json"; a.href = url; a.textContent = "Download backup.json"; ($ == undefined ) ? document.body.appendChild(a) : $("body").append(a);