Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript The Landscape of JavaScript JavaScript Tools and Workflows A JavaScript Developer's Workflow

Craig Kempster
Craig Kempster
4,332 Points

Importing external JSON file using Native JS

I am working on a personal project where I am trying to import an external JSON array file using native Java Script, do you have any videos in the library which explain the process of reading JSON files. I do not wish to use an external library, the idea is to understand the process.

Thank you Craig

3 Answers

Craig Kempster
Craig Kempster
4,332 Points

Thank you Steven, the course was an eye opener

Steven Parker
Steven Parker
231,269 Points

Craig Kempster - Glad to help. But normally, you'd select as "best answer" the answer that contained the information that resolved your issue.   :see_no_evil:

Any comments you might want to make can be added to the question with "add comment" instead of creating another "answer".   :wink:

Steven Parker
Steven Parker
231,269 Points

In the past this would have been a huge pain, but the relatively new native "fetch" function makes this nearly as easy to do as with jQuery:

fetch("array.json")
  .then(response => response.json())
  .then(obj => /* do what you want here with the JSON object "obj" */);

Note that the default security settings of some browsers might not allow loading local files from the computer.

Craig Kempster
Craig Kempster
4,332 Points

Thank You Steven

Is there a JSON course in Treehouse that you are aware of?

Steven Parker
Steven Parker
231,269 Points

Not that I know of, but there's a Working with the Fetch API workshop.