FileSaver.js icon indicating copy to clipboard operation
FileSaver.js copied to clipboard

How to save a "https://xxxxxxxx.json" file

Open tpc-ht opened this issue 4 years ago • 3 comments

saveAs("https://xxxxxxxx.json", "hello.json",); Can be directly opened in the browser, how can I directly save the local

tpc-ht avatar Dec 01 '21 06:12 tpc-ht

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")
    });

mirusu400 avatar May 23 '22 09:05 mirusu400

this is JSON to text/string. How about as JSON ?

ad9999 avatar Feb 09 '23 16:02 ad9999

@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'))

jimmywarting avatar Feb 09 '23 16:02 jimmywarting