Understanding JSON in 5 Minutes

One huge advantage of using JSON when transferring data between applications through networks, is that it is so easy to understand. If you have ever created a dictionary (or map, or hash, symbol table, or associative array – many names for the same idea), then creating JSON will seem very familiar.
The other main advantage of learning to use JSON is that it's virtually impossible to work on internet-savvy applications without coming across it.
So, we've promised 5 minutes, enough of the small talk.

What does JSON stand for?

JavaScript Object Notation

Eh? Javascript??

Yep. Javascript reduces everything to text, including its method of creating objects. Text is easy, and it is ubiquitous, and so the practice of defining objects, and object hierarchies, spread beyond JavaScript. The is no other JavaScript in this article, by the way.

What does it look like?

At it's simplest, it looks like this:
{ “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.