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 Node.js Basics 2017 Building a Command Line Application Planning Our Project

How do we retrieve JSON data from websites?

If I want to get the information from a website, how do I know where to get that JSON formatted information and parse it to my site?

Also, do all the websites offer JSON?

Thanks

1 Answer

Hi Hanwen!

Not all websites offer JSON data. (In fact, I would have to say only a select few actually do.)

And of the websites that do offer it, some make access to it relatively simple, and others make access extremely difficult, often requiring signing up for an account, and/or going through some hoops to prove your identity, acquiring an API key, etc. Some even require payment (usually a monthly subscription) to enable access, often with multiple-tier pricing.

Teamtreehouse, for example, makes access relatively easy and free.

OpenWeatherMap.org is kind of in the middle, offering both free and paid subscription tiers - and provides documentation to instruct you how to correctly access the data.

More info

https://openweathermap.org/api (scroll to the bottom for the documentation)

I use the OpenWeatherMap API here:

https://www.moneyband.org/news.php (in the section labeled "Monterey Weather Stats")

Facebook, on the other hand, makes accessing their API data downright nightmarish. Although free to access, there is an elaborate series of hoops you have to go through to secure what Facebook calls an Access Token.

I feel Facebook makes the process unreasonably difficult (but I would expect nothing less from Facebook, though!?! LOL).

More info:

https://developers.facebook.com/docs/graph-api/using-graph-api#how-to-get-an-access-token

I had to do several weeks of research to learn how to access one Facebook API for getting access to uploaded video data.

Which I am accessing here:

https://www.moneyband.org/video.php

The bottom line is you will have to query the web to locate various appropriate and accessible APIs. And then you will need to do further research to learn how to wire-up your app to access that API correctly. Hopefully, most APIs will provide their own documentation, and even then I often have to still go to other resources to find examples of how to get the access code exactly right.

Here is a list of the top 50 most popular APIs on RapidApi (Including OpenWeatherMap - #2 on the list):

https://rapidapi.com/blog/most-popular-api/ (A good place to learn about APIs, in general)

More info:

https://forum.freecodecamp.org/t/free-api-inspirational-quotes-json-with-code-examples/311373

https://rapidapi.com/collection/quote-generator-apis

I hope that helps.

Stay safe and happy coding!

Hi Peter,

That helps me so much! thank you