0% found this document useful (0 votes)
20K views

JSON Cheat Sheet: by Via

This document provides a cheat sheet for JSON (JavaScript Object Notation) with definitions of basic data types (numbers, strings, booleans, arrays, objects), examples of creating and accessing objects and arrays, and examples of nested objects and accessing nested elements. The cheat sheet defines JSON data types and syntax, demonstrates creating and accessing objects and arrays, and shows examples of nested objects and accessing elements within nested structures.

Uploaded by

Rajendra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20K views

JSON Cheat Sheet: by Via

This document provides a cheat sheet for JSON (JavaScript Object Notation) with definitions of basic data types (numbers, strings, booleans, arrays, objects), examples of creating and accessing objects and arrays, and examples of nested objects and accessing nested elements. The cheat sheet defines JSON data types and syntax, demonstrates creating and accessing objects and arrays, and shows examples of nested objects and accessing elements within nested structures.

Uploaded by

Rajendra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

JSON Cheat Sheet

by Mackan90096 (Mackan90096) via cheatography.com/20748/cs/3634/

Data Types Objects Array of objects (cont)

number var Series of numbers; var myObject = { ​ ​ ​ ​"​fir​st": "​Amy​",


myNum decimals ok; double​- ​ ​"​fir​st": "​Joh​n", ​ ​ ​ ​"​las​t": "​Bur​nqu​ist​",
= pr​ecision
​ ​"​las​t": "​Doe​", ​ ​ ​ ​"​age​": 29,
123.456; floati​ng-​point format
​ ​"​age​": 39, ​ ​ ​ ​"​sex​": "​fem​ale​",
string var Series of characters
​ ​"​sex​": "​mal​e", ​ ​ ​ ​"​sal​ary​": 60000,
myString (letters, numbers, or
​ ​"​sal​ary​": 70000, ​ ​ ​ ​"​reg​ist​ere​d": false
= symbols); double​-
​ ​"​reg​ist​ere​d": true ​ }
"​abc​def​"; quoted UTF-8 with
backslash escaping }; ];

boolean var true or false


myBool = Access object properties Access array elements

true;
myObje​ct.sex returns "​mal​e" myArray[0] returns { "​fis​t": "​Joh​n", "​las​t":
array var sequence of myObje​ct[​"​age​"] returns 39 "​Doe​" ... }
myArray comma-​sep​arated myArray[1] returns { "​fis​t": "​Jan​e", "​las​t":
myObje​ct[0] returns "​Joh​n"
= [ "​a", values (any data "​Smi​th" ... }
"​b", "​c", type); enclosed in myObje​ct.s​om​ething returns undefined
myArra​y[1​].first returns "​Jan​e"
"​d" ]; square brackets myObje​ct[6] returns undefined
myArra​y[1][2] returns 42
object var unordered collection of
myObject comma-​sep​arated Array of objects myArra​y[2​].r​egi​ returns false
= { "​id": 7 key/value pairs; stered
var myArray = [
}; enclosed in curly myArray[3] returns undefined
braces; properties ​ {
myArra​y[3​].sex error: "​cannot read
(keys) are distinct ​ ​ ​ ​"​fir​st": "​Joh​n",
proper​ty..."
strings ​ ​ ​ ​"​las​t": "​Doe​",

null var variable with null ​ ​ ​ ​"​age​": 39,


Arrays
myNull = (empty) value ​ ​ ​ ​"​sex​": "​mal​e",
null; ​ ​ ​ ​"​sal​ary​": 70000, var myArray = [

undefined var variable with no value ​ ​"​Joh​n",


​ ​ ​ ​"​reg​ist​ere​d": true
myUnde​fi assigne ​ }, ​ ​"​Doe​",
ned; ​ 39,
​ {
​ ​"​M",
​ ​ ​ ​"​fir​st": "​Jan​e",
​ ​ ​ ​"​las​t": "​Smi​th", ​ ​70000,

​ ​ ​ ​"​age​": 42, ​ true


];
​ ​ ​ ​"​sex​": "​fem​ale​",
​ ​ ​ ​"​sal​ary​": 80000,
​ ​ ​ ​"​reg​ist​ere​d": true
​ },
​ {

By Mackan90096 Published 9th March, 2015. Sponsored by CrosswordCheats.com


(Mackan90096) Last updated 9th March, 2015. Learn to solve cryptic crosswords!
Page 1 of 2. http://crosswordcheats.com

cheatography.com/mackan90096/
JSON Cheat Sheet
by Mackan90096 (Mackan90096) via cheatography.com/20748/cs/3634/

Access array elements Access nested elements

myArray[1] returns "​Doe​" myObje​ct.r​ef.first returns 0

myArray[5] returns true myObje​ct.j​doe1 returns [ "​Joh​n",


"​Doe​", 39 ... ]
myArray[6] returns undefined
myObje​ct[2] returns [ "​Jan​e",
Nested objects and arrays "​Smi​th", 42 ... ]

myObje​ct.j​sm​ith1[3] returns "​fem​ale​"


var myObject = {
​ ​"​ref​": { myObje​ct[​1][5] returns true

​ ​ ​ ​"​fir​st": 0, myObje​ct.j​do​e1[​myO​bje​ct returns "​Doe​"

​ ​ ​ ​"​las​t": 1, .r​ef.last]

​ ​ ​ ​"​age​": 2, myObje​ct.j​sm​ith​1[m​yOb​j returns 42

​ ​ ​ ​"​sex​": 3, ec​t.r​ef.age]

​ ​ ​ ​"​sal​ary​": 4,
​ ​ ​ ​"​reg​ist​ere​d": 5
​ },
​ ​"​jdo​e1": [
​ ​ ​ ​"​Joh​n",
​ ​ ​ ​"​Doe​",
​ ​ ​ 39,
​ ​ ​ ​"​mal​e",
​ ​ ​ ​70000,
​ ​ ​ true
​ ],
​ ​"​jsm​ith​1": [
​ ​ ​ ​"​Jan​e",
​ ​ ​ ​"​Smi​th",
​ ​ ​ 42,
​ ​ ​ ​"​fem​ale​",
​ ​ ​ ​80000,
​ ​ ​ true
​ ]
};

By Mackan90096 Published 9th March, 2015. Sponsored by CrosswordCheats.com


(Mackan90096) Last updated 9th March, 2015. Learn to solve cryptic crosswords!
Page 2 of 2. http://crosswordcheats.com

cheatography.com/mackan90096/

You might also like