Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Asynchronous Programming with JavaScript Understanding Promises Using Fetch

Is .json() the same as JSON.parse()?

Title

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Kirt Perez! They are very similar, but not exactly the same. Yes, they both create JSON. However, the .json() is asynchronous and returns a Promise. While the JSON.parse is synchronous. The .json() takes the Response and turns it into JSON while the JSON.parse() takes a JSON formatted string and returns any one of a few data types.

For more information, I recommend the following:

Hope this helps! :sparkles:

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree
karan Badhwar
Web Development Techdegree Student 13,921 Points

Hi, Jennifer Nordell, but on MDN it says, it returns a JavaScript Object not the JSON file. As, if it returns a JSON file, then how are we using it and extracting the JSON file to an Array of Objects to use. Moreover, @Guil also said it returns a JSON , but if it is returning the JSON, then where are we actually parsing the file into an array ?

MDN explanation below: -

Note that despite the method being named json(), the result is not JSON but is instead the result of taking JSON as input and parsing it to produce a JavaScript object.