Last active
July 8, 2023 10:24
-
-
Save gauravpan/95e401b83533abba148fbf18eeff518f to your computer and use it in GitHub Desktop.
Create and download JSON file on browser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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