Show Menu
Cheatography

A JSON cheat sheet.

Data Types

number
var myNum = 123.456;
Series of numbers; decimals ok; double­-pr­ecision floati­ng-­point format
string
var myString = "­abc­def­";
Series of characters (letters, numbers, or symbols); double­-quoted UTF-8 with backslash escaping
boolean
var myBool = true;
true or false
array
var myArray = [ "­a", "­b", "­c", "­d" ];
sequence of comma-­sep­arated values (any data type); enclosed in square brackets
object
var myObject = { "­id": 7 };
unordered collection of comma-­sep­arated key/value pairs; enclosed in curly braces; properties (keys) are distinct strings
null
var myNull = null;
variable with null (empty) value
undefined
var myUnde­fined;
variable with no value assigne
 

Objects

var myObject = {
  "first": "John",
  "last": "Doe",
  "age": 39,
  "sex": "male",
  "salary": 70000,
  "registered": true
};

Access object properties

myObje­ct.sex
returns "­mal­e"
myObje­ct[­"­age­"]
returns 39
myObje­ct[0]
returns "­Joh­n"
myObje­ct.s­om­ething
returns undefined
myObje­ct[6]
returns undefined

Array of objects

var myArray = [
  {
    "first": "John",
    "last": "Doe",
    "age": 39,
    "sex": "male",
    "salary": 70000,
    "registered": true
  },
  {
    "first": "Jane",
    "last": "Smith",
    "age": 42,
    "sex": "female",
    "salary": 80000,
    "registered": true
  },
  {
    "first": "Amy",
    "last": "Burnquist",
    "age": 29,
    "sex": "female",
    "salary": 60000,
    "registered": false
  }
];

Access array elements

myArray[0]
returns { "­fis­t": "­Joh­n", "­las­t": "­Doe­" ... }
myArray[1]
returns { "­fis­t": "­Jan­e", "­las­t": "­Smi­th" ... }
myArra­y[1­].first
returns "­Jan­e"
myArra­y[1][2]
returns 42
myArra­y[2­].r­egi­stered
returns false
myArray[3]
returns undefined
myArra­y[3­].sex
error: "­cannot read proper­ty..."
 

Arrays

var myArray = [
  "John",
  "Doe",
  39,
  "M",
  70000,
  true
];

Access array elements

myArray[1]
returns "­Doe­"
myArray[5]
returns true
myArray[6]
returns undefined

Nested objects and arrays

var myObject = {
  "ref": {
    "first": 0,
    "last": 1,
    "age": 2,
    "sex": 3,
    "salary": 4,
    "registered": 5
  },
  "jdoe1": [
    "John",
    "Doe",
    39,
    "male",
    70000,
    true
  ],
  "jsmith1": [
    "Jane",
    "Smith",
    42,
    "female",
    80000,
    true
  ]
};

Access nested elements

myObje­ct.r­ef.first
returns 0
myObje­ct.j­doe1
returns [ "­Joh­n", "­Doe­", 39 ... ]
myObje­ct[2]
returns [ "­Jan­e", "­Smi­th", 42 ... ]
myObje­ct.j­sm­ith1[3]
returns "­fem­ale­"
myObje­ct[­1][5]
returns true
myObje­ct.j­do­e1[­myO­bje­ct.r­ef.last]
returns "­Doe­"
myObje­ct.j­sm­ith­1[m­yOb­jec­t.r­ef.age]
returns 42
           

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi
 

Comments

Great reference, very handy!

You carried over some typos from https://www.json.com/cheat-sheet-v-1-3

You might correct "fist" to "first" in a few places.

I having some difficulty downloading the JSON cheatsheet I probably need to Add a Comment.

Still having difficulty download loading PDF of JSON Cheatsheet.

Great cheatsheet.

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          More Cheat Sheets by Mackan90096

          Sublime Text 3 Windows Keyboard Shortcuts