.json

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Yeet

What is JSON?[edit]

JSON, also known as JavaScript Object Notation, is a text-based, human-readable data interchange format. The filetype used is .json and is based off of a subset of the JavaScript lnaguage. The .json format is completely text-based, and was created back in 2001 by Douglas Crockford. It was later standardized in 2006 through the IETF (Internet Engineering Task Force) under RFC 4627. All modern programming languages also provide support for producing and consuming .json data.

Why use JSON?[edit]

Because the file format is text only, JSON data can be easily sent between computers and implemented in various ways.

Uses of JSON[edit]

JSON Syntax[edit]

Below is a sample of JSON syntax:

{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "office",
      "number": "646 555-4567"
    }
  ],
  "children": [],
  "spouse": null
}

JSON is formatted similar to a dictionary, with key and value pairs.

There are a few key tricks to learning how to read and write in .json files:

  • Curly braces {...} contain objects
  • Square brackets [...] contain arrays
  • Data is stored in name-value pairs separated by a colon, :
  • Every data pair and item in an array are separated by a comma ,
  • JSON property names must be within quotations "..."

References[edit]