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 Building a MEAN Application Going MEAN with Express Setting Up an Express API

I added 'res.send({todos:[]});' but it is not converted to json in the browser? (unlike video)

When I went through the step of adding "res.send({todos:[]}" to the api GET method, it does not convert to a JSON object like it does in the video. I also tried changing the command from 'res.send' to 'res.json' but it still returns exactly as written in the function, instead of the formatting changing to that of JSON like it does in the video.

ex. it shows {todos:[]} in the browser, instead of...

{ todos: [] }

4 Answers

Seth Kroger
Seth Kroger
56,414 Points

The only difference between the two is formatting. Unformatted, it's usually compressed into a single line without spacing. Huston is almost certainly using a browser extension to display JSON in a more readable way. (JSONView is one; available on Firefox and Chrome).

Good to know! I won't worry about it too much then - thank you!

That's the correct behavior if you're watching this video that's attached to your question. Calling for dummy data happens in the other video.

I think I'm a little confused - are you saying it should be expanding to display in JSON format? So far I've only watched the video attached to my question which is where I noticed that behavior (which wasn't occurring on my machine). The other answer suggested that it may be a browser extension on the instructors machine which is making it display in JSON format.

Nathan Minarik
Nathan Minarik
590 Points

Yeah you should get this extension (very useful for any project which you're working with JSON data on) https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc

JSONview has since been deprecated for Chrome. I would suggest using the extension JSON Formatter instead.

https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa/related?hl=en