JSON (JavaScript Object Notation) is a lightweight data interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. JSON is a text format that is completely language-independent but uses conventions that are familiar to programmers of the C family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. Let’s start 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

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

Access array elements
myArray[0]
returns { “­firs­t”: “­Joh­n”, “­las­t”: “­Doe­” … }
myArray[1]
returns { “­firs­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

Access array elements
myArray[1]
returns “­Doe­”
myArray[5]
returns true
myArray[6]
returns undefined
Nested objects and arrays

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
JSON Cheat Sheet

Leave a Comment