Skip to content

Instantly share code, notes, and snippets.

@petermeissner
Created April 30, 2021 19:08
Show Gist options
  • Save petermeissner/c15f178711266405528ed751cf0cb5fb to your computer and use it in GitHub Desktop.
Save petermeissner/c15f178711266405528ed751cf0cb5fb to your computer and use it in GitHub Desktop.
Download JSON file from webpage
function date(){
var date = new Date();
return date.toISOString().substr(0,10);
}
function download(content, filename, contentType) {
if(!contentType) contentType = 'application/octet-stream';
var a = document.createElement('a');
var blob = new Blob([content], {'type':contentType});
a.href = window.URL.createObjectURL(blob);
a.download = filename;
a.click();
}
my_data = {
key: "value",
another_key: [1,2,3,4,5,6,7,8,9,0]
}
download(JSON.stringify(my_data), "json_data_" + date() + ".json", "application/json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment