Skip to content

Instantly share code, notes, and snippets.

@gauravpan
Last active July 8, 2023 10:24
Show Gist options
  • Select an option

  • Save gauravpan/95e401b83533abba148fbf18eeff518f to your computer and use it in GitHub Desktop.

Select an option

Save gauravpan/95e401b83533abba148fbf18eeff518f to your computer and use it in GitHub Desktop.
Create and download JSON file on browser.
function downloadFile(filename, data) {
let element = document.createElement("a");
element.setAttribute("download", filename);
element.setAttribute("href", data);
document.body.appendChild(element);
element.click();
}
downloadFile(
`file_name`,
`data:application/json;plain,${JSON.stringify({ name: `hello world!!` })}`
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment