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

Leroy Sibisi
Leroy Sibisi
20,619 Points

I'm having a problem answering this challenge.

I'm having a problem answering this challenge.

The challenge is, Create a new variable jsonObject and then use the native JSON object to parse the jsonString and assign it to jsonObject.

Here is the code provided; var jsonString = '{"name": "Andrew", "languages": ["javascript", "swift", "java", "ruby", "html", "css", "qbasic"]}';

My answer was; var jsonObject = JSON.parse("jsonString");

But I get an error.

4 Answers

In your answer, you have jsonString as an actual string using the quotes JSON.parse("jsonString");

it should be the variable
JSON.parse(jsonString);

also for reference, I tried to add my new variable to the top. and it wouldn't work:

ex 1.

var jsonObject = JSON.parse(jsonString);
var jsonString = '{"name": "Andrew", "languages": ["javascript", "swift", "java", "ruby", "html", "css", "qbasic"]}';

However, when i added it below the jsonString, it was correct.

ex 2.

var jsonString = '{"name": "Andrew", "languages": ["javascript", "swift", "java", "ruby", "html", "css", "qbasic"]}';
var jsonObject = JSON.parse(jsonString);

hope that helps.

Sathish kumar Balasubramanian
Sathish kumar Balasubramanian
6,748 Points

The answer is

var jsonObject = JSON.parse('jsonString');

"JSON" all in caps in JSON.parse() method.

Please refer the native Javascript documentation. Here is the link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

Close! But your jquery keyword is a bit off, check the documentation for a clue:
https://api.jquery.com/jquery.parsejson/

Leroy Sibisi
Leroy Sibisi
20,619 Points

I looked at the documentation, then change the answer to

var jsonObject = jQuery.parseJSON("jsonString");

Still, I haven't had any luck! :-(

Close! But your jquery keyword is a bit off, check the documentation for a clue:
https://api.jquery.com/jquery.parsejson/