Skip to content

Instantly share code, notes, and snippets.

@Maes95
Created March 12, 2017 19:27
Show Gist options
  • Save Maes95/903ce7d54d60bbda744687944866de52 to your computer and use it in GitHub Desktop.
Save Maes95/903ce7d54d60bbda744687944866de52 to your computer and use it in GitHub Desktop.
function exportAsJSON(fileName, myJsonObject){
var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(myJsonObject));
var a = document.createElement('a');
a.href = "data: "+data;
a.download = fileName+".json";
a.click();
}
var someData = {
name: "John",
age: 23
}
exportAsJSON("john", someData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment