Exercises: JSON
Which of the following three code snippets is correct JSON syntax? Why are the other two options incorrect?
a.
1 2 3 4 5
{ type: "dog", name: "Bernie", age: 3 }
b.
1 2 3 4 5
{ "type": "dog", "name": "Bernie", "age": 3 }
c.
1 2 3 4 5
{ "type": 'dog', "name": 'Bernie', "age": 3 }
Which of the following three code snippets is correct JSON? Why are the other two options incorrect?
a.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{ "animals": [ { "type": "dog", "name": "Bernie", "age": 3 }, { "type": "cat", "name": "Draco", "age": 2 } ] }
b.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{ [ { "type": "dog", "name": "Bernie", "age": 3 }, { "type": "cat", "name": "Draco", "age": 2 } ] }
c.
1 2 3 4 5 6 7 8 9 10 11 12
[ { "type": "dog", "name": "Bernie", "age": 3 }, { "type": "cat", "name": "Draco", "age": 2 } ]