FileSaver.js
FileSaver.js copied to clipboard
How to save a "https://xxxxxxxx.json" file
saveAs("https://xxxxxxxx.json", "hello.json",); Can be directly opened in the browser, how can I directly save the local
A little late answer, but you can fetch json, stringify, and save as blob you can download it.
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
.then(json => JSON.stringify(json))
.then(json => {
const blob = new Blob([json], { type: "text/plain;charset=utf-8" });
saveAs(blob, "out.txt")
});
this is JSON to text/string. How about as JSON ?
@mirusu400 you don't need to fetch it as json. you can just download it as a blob directly
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.blob())
.then(blob => saveAs(blob, 'out.txt'))