Intro

JSON (JavaScript Object Notation) is a commonly used data format for storing and transporting data. JSON uses a text-based structure using key-value pairs, which facilitates easy data exchange between servers and clients.

Though it was derived from Javscript, JSON is language and platform independent.

JSON Syntax Rules

  • Data is in name/value pairs
  • Curly braces hold objects
  • Square brackets hold arrays
  • Multiple values are separated by commas

Example JSON respresentation describing a person:

{
  "first_name": "John",
  "last_name": "Smith",
  "is_alive": true,
  "age": 27,
  "address": {
    "street_address": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postal_code": "10021-3100"
  },
  "phone_numbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [
    "Catherine",
    "Thomas",
    "Trevor"
  ],
  "spouse": null
}

Processing JSON

Different programming languages and frameworks provide various ways to generate and parse JSON data.