A very simple example of JSON is:
{ "name":"James", "age":"30", "country":"France" }
Key-value pair or name-value pair syntax of JSON
- JSON starts with
{
(left brace). - JSON ends with
}
(right brace). - Keys in JSON are string in double quotes.
- Key and value in JSON is separated by
:
(colon). - Each key-value pair in JSON is separated by
,
(comma).
JSON is based on two structures:
- JSON is a collection of name/value pairs. Various languages have different ways to represent a collection of name/value pairs. For example, object, hash table, hash map, struct, dictionary etc.
- An ordered list of values. This is generally represented as array, list, vector or sequence.
JSON as a document and MediaType
- JSON can be saved in your file system. The extension of such file should be
.json
. - The MIME type or media type for JSON is
application/json
.
Important Note
- You can use special characters in “name” but this should be avoided to avoid portability issues.
- In the JSON name-value pair, it is mandatory to have double quotes (“) around name.
- In the JSON name-value pair, the value can be a string, boolean, number, null,object, or array.