Book
Submodule 13.3: Object Notation
Submodule 13.3: Object Notation
Completion requirements
View
- What is JSON?
- JSON structure
- Arrays as JSON
JSON syntax
An example of a JSON object is:
{
"dishes": [
{
"id": 0,
"name": "85% Dark Chocolate",
"image": "images/dark85.jpg",
"category": "darks",
"label": "Hot",
"price": "4.99",
"featured": "true",
"description": "Dark chocolate with no added sugar. Here you can taste the flavor of cocoa beans."
}
]
}
Based on the above, let's analyze the syntax :
- They are surrounded by curly brackets { }
- They have key( eg "id")-value( eg 0) pairs.
- Each key-value pair is separated from the next one with a comma
- Each key is separated from its value by a colon
- Each key must be a string and written with double quotes
- Objects contain arrays ( in this case 1 array) which should be surrounded by Square brackets
In our example, the object "dishes" is an array. It contains 1 object.