JMU
JavaScript Object Notation (JSON)
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Motivation
Elements
Identifying JSON Files
An Example

A Single Object

jsonexamples/basics/person.json
{
    "firstName": "John",
    "lastName": "Doe",
    "age": 53,
    "address": {
        "streetAddress": "879 Paul St.",
        "city": "Harrisonburg",
        "state": "VA",
        "postalCode": 22801
    },
    "phoneNumbers": [
        "540-434-5555",
        "540-568-4411",
        "540-555-1234" 
    ] 
}
        
An Example

An Array of Objects

jsonexamples/basics/incidents.json
{
  "date": "1 Jan 2001",
  "breakdowns": [
    {
      "description": "Minivan ran out of gas on I81"
    },
    {
      "description": "Minivan with engine trouble on Rt. 42"
    },
    {
      "description": "Minivan with flat tire on Main St."
    }
  ],
  "accidentReports": [
    {
      "size": 1,
      "type": "Overturned poultry truck on Port Rd."
    },
    {
      "size": 2,
      "type": "Head-on crash on I81 at Exit 245"
    }
  ]
}