0% found this document useful (0 votes)
8 views

Json Cheatsheet

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

Json Cheatsheet

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; ​ ​"​fir​st": "​Joh​n", ​ ​ ​ ​"​las​t": "​Bur​nqu​ist​",
= double​-pr​ecision ​ ​"​las​t": "​Doe​", ​ ​ ​ ​"​age​": 29,
123.456; floati​ng-​point ​ ​"​age​": 39, ​ ​ ​ ​"​sex​": "​fem​ale​",
format ​ ​"​sex​": "​mal​e", ​ ​ ​ ​"​sal​ary​": 60000,
string var Series of ​ ​"​sal​ary​": 70000, ​ ​ ​ ​"​reg​ist​ere​d": false
myString characters (letters, ​}
​ ​"​reg​ist​ere​d": true
= "​abc​‐ numbers, or ];
};
def​"; symbols); double​-
quoted UTF-8 with Access array elements
Access object properties
backslash myArray[0] returns { "​fis​t": "​Joh​n", "​las​‐
myObje​ct.sex returns "​mal​e"
escaping t": "​Doe​" ... }
myObje​ct[​"​age​"] returns 39
boolean var true or false myArray[1] returns { "​fis​t": "​Jan​e", "​las​‐
myBool = myObje​ct[0] returns "​Joh​n"
t": "​Smi​th" ... }
true; myObje​ct.s​om​ething returns undefined
myArra​‐ returns "​Jan​e"
array var sequence of myObje​ct[6] returns undefined y[1​].first
myArray comma-​sep​arated
myArra​y[1][2] returns 42
= [ "​a", "​‐ values (any data Array of objects
myArra​y[2​].r​‐ returns false
b", "​c", "​‐ type); enclosed in
var myArray = [ egi​stered
d" ]; square brackets
​ {
myArray[3] returns undefined
object var unordered ​ ​ ​ ​"​fir​st": "​Joh​n",
myObject collection of myArra​‐ error: "​cannot read proper​‐
​ ​ ​ ​"​las​t": "​Doe​",
= { "​id": 7 comma-​sep​arated y[3​].sex ty..."
​ ​ ​ ​"​age​": 39,
}; key/value pairs;
​ ​ ​ ​"​sex​": "​mal​e",
enclosed in curly Arrays
​ ​ ​ ​"​sal​ary​": 70000,
braces; properties var myArray = [
​ ​ ​ ​"​reg​ist​ere​d": true
(keys) are distinct ​ ​"​Joh​n",
​ },
strings ​ ​"​Doe​",
​ {
null var variable with null ​ 39,
​ ​ ​ ​"​fir​st": "​Jan​e",
myNull = (empty) value ​ ​"​M",
​ ​ ​ ​"​las​t": "​Smi​th",
null; ​ ​70000,
​ ​ ​ ​"​age​": 42,
undefined var variable with no ​ true
​ ​ ​ ​"​sex​": "​fem​ale​",
myUnde​‐ value assigne ];
​ ​ ​ ​"​sal​ary​": 80000,
fined;
​ ​ ​ ​"​reg​ist​ere​d": true
​ },
​ {

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


(Mackan90096) Last updated 12th May, 2016. Everyone has a novel in them. Finish
Page 1 of 2. Yours!
https://apollopad.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", "​‐
myArray[6] returns undefined Doe​", 39 ... ]
myObje​ct[2] returns [ "​Jan​e", "​‐
Nested objects and arrays Smi​th", 42 ... ]

var myObject = { myObje​ct.j​sm​ith1[3] returns "​fem​ale​"


​ ​"​ref​": { myObje​ct[​1][5] returns true
​ ​ ​ ​"​fir​st": 0, myObje​ct.j​do​e1[​myO​‐ returns "​Doe​"
​ ​ ​ ​"​las​t": 1, bje​ct.r​ef.last]
​ ​ ​ ​"​age​": 2,
myObje​ct.j​sm​ith​1[m​‐ returns 42
​ ​ ​ ​"​sex​": 3, yOb​jec​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 ApolloPad.com


(Mackan90096) Last updated 12th May, 2016. Everyone has a novel in them. Finish
Page 2 of 2. Yours!
https://apollopad.com
cheatography.com/mackan90096/

You might also like