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 trialA X
12,842 Points2 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
231,172 PointsAnonymous 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
Treehouse Moderator 145,860 PointsHey 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! :)
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsGood catch Steven,
I didn't even notice the second set of {} in his code... No more multi-tasking for me tonight. Lol.