The JSON Syntax contains the next elements:
- data is represented in key/value pair separated by colon (:) key : value
- comma (,) separates the key/value pairs key : value , key : value
- object groups multiple key/value pairs and are held by curly brackets ({}) { key : value , key : value }
- arrays group multiple objects separated by comma (,) and are held by square brackets ([]) [ { key : value , key : value },{ key : value , key : value } ]
Depending on the data type, you could need to write the key and values in double quotes.
JSON Example
{
"city": [
{
"id": 1,
"name": "Zaragoza",
"country": "Spain",
"population": 680000
},
{
"id": 2,
"name": "Bristol",
"country": "England",
"population": 550000
}
]
}
Data Types
In JSON, values must be one of the next data types:
- Number : double precision floating-point format
- String : double quoted (“) Unicode
- Boolean : true or false
- null
If you need to include functions, dates, or undefined values, you cannot use JSON. See JSON vs XML page to find out more.