JavaScript AJAX Basics Programming AJAX Finish the JSON File

Jaima Zollinger
Jaima Zollinger
5,440 Points

Not 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,

songs.json
[ 
  {
    "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
PRO
Zhaopeng Wang
Full Stack JavaScript Techdegree Graduate 30,870 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
Jaima Zollinger
5,440 Points

THANK YOU!!! I was adding the commas everywhere except after the closing bracket of each object.