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 trialJaima Zollinger
5,832 PointsNot understanding where to place commas in JSON
I have not been able to figure out where to place the commas in this challenge. No matter what I do I'm getting an error code. I've tried it three different ways all with conflicting errors. I think this post is going to attach my final attempt, which was a last ditch effort to get it to work. I got rid of the brackets and tried to list everything together with a comma after each item excluding the last and the error says "there should be four songs in this file"
First I tried with the following code:
[ { "title" : "My Way", "artist" : "Frank Sinatra" } { "title" : "song one", "artist" : "me" } { "title" : "song two", "artist" : "not me" } { "title" : "song three", "artist" : "my children" } ]
For the code above I got the error that I was missing commas between the objects, so I tried this...
[ { "title" : "My Way", "artist" : "Frank Sinatra", } { "title" : "song one", "artist" : "me", } { "title" : "song two", "artist" : "not me", } { "title" : "song three", "artist" : "my children" } ]
And I got the error that I have too many commas.
Can someone please point me in the right direction?
Thank you,
[
{
"title" : "My Way",
"artist" : "Frank Sinatra",
"title" : "song one",
"artist" : "me",
"title" : "song two",
"artist" : "not me",
"title" : "song three",
"artist" : "my kids"
}
]
1 Answer
Zhaopeng Wang
Full Stack JavaScript Techdegree Graduate 32,210 Points- []-->array
- {}-->object
- It is an array containing 4 objects, therefore, you put the comma between each object
[
{
"title" : "My Way",
"artist" : "Frank Sinatra"
},
{
"title" : "My Way",
"artist" : "Frank Sinatra"
},
{
"title" : "My Way",
"artist" : "Frank Sinatra"
},
{
"title" : "My Way",
"artist" : "Frank Sinatra"
}
]
Jaima Zollinger
5,832 PointsJaima Zollinger
5,832 PointsTHANK YOU!!! I was adding the commas everywhere except after the closing bracket of each object.