{ “myKey” : myVal }
The key, as we can see, is a quoted string. Any legal string will do.
The value can be a string too, but can also be a number, a boolean, another JSON object, or an array of any of these data types. It can also be null, meaning none of the above.
Data Types?
Ok, here it is again as a list:
String
Number
Boolean
Object
Array
And when it's not at its simplest?
A JSON object can contain several key-value pairs, separated by commas:
{
"monday" : 1,
"tuesday" : 2,
“wednesday" : 3
}
A JSON object can contain values of mixed type:
{
"myName" : "Eric B",
"myNumber" : 0.5
}
A JSON object can contain values that are themselves JSON objects:
{
"myID" : 12345,
"myData" : {
"name" : "Doug",
"Fave Composer" : "Bach"
}
}
Such a nested JSON object can be an array:
{
"myID" : 12345,
"myData" : [1, 2, 3]
}
Arrays are comma-separated lists of values inside square brackets. Such an array can also contain mixed types:
{
"myID" : 12345,
"myData" : [1,2,"Buckle my shoe"]
}
And you can continue nesting objects in objects, and arrays of arrays in objects, and whatever other combination you can dream up.
The rest is just more of the same. It's a simple model.
In whatever language you programme, you'll find libraries that will encode your native data structures (on the whole, dictionaries aka maps aka hashes) into JSON data to be included in the body of an HTML request. And of course those libraries will also decode HTTP response data into native data structures.
Where to go next
If Swift is your language of choice, check out Apple's mini-json-tutorial
here.