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 (2014) Building a Command Line Application Parsing JSON

stage 2 cmd line

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

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

I tried both string and object. It won't work. var jsonObject = JSON.parse(jsonObject);

4 Answers

Hi Ellie,

You need to set one line of var jsonString together, not separate

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

how?

We should leave the first line, you just press enter to go second line to add the second code just like above.

Example:

 var var1 = '{"name":...., "languages": [......]}';
 var result = JSON.parse(var1);

I don' t get it. I already have this code.

I think Salman is saying you accidentally inserted a line break in your code, which might be causing the problem. It looks like you may have hit enter after "languages": in order to make the code more readable, but it's causing a problem with JSON.parse().

thanks!