Read external JSON in JavaScript

What method can you use to read a local JSON file in Javascript for processing?


What method can you use to read a JSON file hosted on a gist onto a Javascript file for processing?


What framework/library can do any of these two with minimal effort?

Thanks in advance.

  1. you can’t read/write to local files in JS with just browser based Javascript script, you need node.js for that

  2. as long as you have a working link to the gist you can use any api fetching method , third party like axios, jquery, … or the native fetch

  3. you don’t need a framework or lib for the above, but you do need node to to read local files

Node’s require worked for me earlier for a local file. But since you mentioned jQuery, which of the two would be simpler or better? I’m eventually using gist for the final product. I wanted something for local development without depending on a gist. For now.

Do you have a working link to the gist with the JSON data /api? If so I’d just go with fetch

Note, for server side fetch you would need to download fetch from npm as it doesn’t come natively with node as it does client side

1 Like

Na just front end use. Thanks for your help.

Reading Local or External JSON files can be done from lots of methods. I really find jQuery getJSON method very useful when reading JSON.

Yeah fetch did it for me both locally and from an API. Thanks.

1 Like