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 AJAX Basics (retiring) Programming AJAX Create a JSON file

2 Questions about Challenge on JSON Basics

1) In the challenge it asks you to create an empty object. I hesitated to put the answer as [{}] because in other languages wouldn't this error? Why is this acceptable in JSON to have a completely empty object (just the curly braces)...like not even a name for the object...?

2) In the final part of the challenge it asks you to Add an Artist property. Why would this interpretation of the answer be wrong? Am I misunderstanding what the term property means here?

[
{"title": "Naruto"},
{"song: "Wind"} 
]

2 Answers

Steven Parker
Steven Parker
217,639 Points

:point_right: Anonymous objects are allowed in both JSON and JavaScript.

Any object without a name is considered "anonymous". These can include simple objects, arrays, or functions. In fact, anonymous functions are not only allowed, but are very commonly used in JavaScript.

For your second question, the challenge asked you to add an "artist" property to the same object that had the "title" property. In your code above, you have created a second object that has only a "song" property, and you omitted the closing quote mark from the property name.

Following the challenge instructions would result in something more like this:

[
{"title": "Naruto",
 "artist": "Wind"} 
]
Jason Anders
Jason Anders
Treehouse Moderator 145,627 Points

Good catch Steven,

I didn't even notice the second set of {} in his code... No more multi-tasking for me tonight. Lol. :pensive:

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,627 Points

Hey there,

First, no an 'empty object' won't error in other languages (at least not the ones I'm familiar with). If fact, in Object Oriented Programming, you'll often initialize an empty array, dictionary, etc to be used later on.

Second, the code you posted is failing the last part of the challenge because the task (#4) explicitly asks you to add an "artist" and you are adding a "song" (and you are missing the closing quote for the key too).

So, just change "song" to "artist" (challenges are very specific) and you're good to go.

Keep Coding! :) :dizzy: