Skip to content

Instantly share code, notes, and snippets.

@gonaumov
Created June 13, 2023 15:05
Show Gist options
  • Save gonaumov/d96bc272211a799fff9ae255408a9393 to your computer and use it in GitHub Desktop.
Save gonaumov/d96bc272211a799fff9ae255408a9393 to your computer and use it in GitHub Desktop.
// imagine this is the place where you usually
// get the response in the normal application
// you need just to pass here result variable
// it will create a .txt file with the json
// and download it. You need just to reuse this
// mock file later.
const element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(results, null, ' ')));
element.setAttribute('download', 'data.txt');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment