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!
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
Amandeep Pasricha14,932 Points
Eric M11,545 Points
JSON is a data format used by many languages. Most information is not parsed to a programming language but to a data structure that the programming language can interact with. It is possible for a web request to return all sorts of data. I might have an API endpoint
mywebsite.com/hello that returns an mp3 file of me saying "hello". How is this communicated? All data is ultimately represented as bytes and a program needs to be told what sort of encoding those bytes use to represent their information. The encoding for JSON text and mp3 audio are of course different.
Here we know that the endpoint will return JSON, so we tell the program to interpret the data it receives as though it were JSON. If the data is not JSON, this will cause an error in the parser. If it is JSON our program will continue with whatever operations on the JSON we want to perform.
After the data is parsed as JSON we can turn it into an object, or extract one part of the JSON and store it is a string, or integer, or whatever is appropriate.
Guil misspeaks. The time I think you are referring to is at 04:30.