loading...

re: How can I read a local JSON file in HTML/JavaScript? VIEW POST

FULL DISCUSSION
 

So you could run a super simple local file server? One of the 1 line things and that will serve folders from your local machine so you can get them with fetch.

npm i -g serve

cd yourFolder

serve

then in your code you can use

   async function getMyFile() {
       let response = await fetch('http://localhost:3000/mydata.json')
       let data = await response.json()
       return data
   }
 

I love your approach, and I know it's almost impossible to do w/o a server/localhost webserver, but it seems a little complicated of an approach, but thank you for your contribution. I will use this if I have something more complicated.

code of conduct - report abuse