What is JSON?

JSON

JavaScript Object Notation is a data format used extensively on the web. It was developed for easy parsing within JavaScipt.

JSON is written in key|value pairs "first_name" : "John"

  • Array:
{
  "employees" : [ "John", "Cody", "Olivia"]
}
  • Objects can have several sub-object:
{
  "employee" : { 
    "name" : "John", 
    "age" : 82,
    "city" : "Canada"
  }
}
  • An object with objects and an array:
{
  "name" : "Stephano",
  "age" : 34,
  "friends" : ["Susan", "Eric", "Katie"],
  "datetime" : "20170215T123719"
}

Example JSON from the Twitter API

{ 
  created_at: 'Wed Feb 08 21:37:22 +0000 2017',
  id: 829444033101586400,
  id_str: '829444033101586440',
  text: 'In a Rare Zoo Escape, Sunny the Red Panda Is Still at Large https://t.co/mhOT4z8NIu https://t.co/8vHtTlqbmQ',
  display_text_range: [ 0, 83 ],
  source: '<a href="http://publicize.wp.com/" rel="nofollow">WordPress.com</a>',
  user: { 
    id: 972385555,
    id_str: '972385555',
    name: 'Walkileaks',
    screen_name: 'walkileaks',
    location: 'United States',
    url: 'http://www.walkileaks.com',
    protected: false,
    utc_offset: -28800,
    is_translator: false,
    notifications: null 
  },
  geo: null,
  coordinates: null,
  place: null,
  contributors: null,
  is_quote_status: false,
  retweet_count: 0,
  favorite_count: 0,
  entities: { 
    hashtags: [],
    urls: [ [Object] ],
    user_mentions: [],
    symbols: [],
    media: [ [Object] ] 
  },
  extended_entities: { media: [ [Object] ] },
  timestamp_ms: '1486589842473'
}