Data Typesnumber | var myNum = 123.456; | Series of numbers; decimals ok; double-precision floating-point format | string | var myString = "abcdef"; | 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-separated values (any data type); enclosed in square brackets | object | var myObject = { "id": 7 }; | unordered collection of comma-separated key/value pairs; enclosed in curly braces; properties (keys) are distinct strings | null | var myNull = null; | variable with null (empty) value | undefined | var myUndefined; | variable with no value assigne |
| | Objectsvar myObject = {
"first": "John",
"last": "Doe",
"age": 39,
"sex": "male",
"salary": 70000,
"registered": true
};
|
Access object propertiesmyObject.sex | returns "male" | myObject["age"] | returns 39 | myObject[0] | returns "John" | myObject.something | returns undefined | myObject[6] | returns undefined |
Array of objectsvar 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 elementsmyArray[0] | returns { "fist": "John", "last": "Doe" ... } | myArray[1] | returns { "fist": "Jane", "last": "Smith" ... } | myArray[1].first | returns "Jane" | myArray[1][2] | returns 42 | myArray[2].registered | returns false | myArray[3] | returns undefined | myArray[3].sex | error: "cannot read property..." |
| | Arraysvar myArray = [
"John",
"Doe",
39,
"M",
70000,
true
];
|
Access array elementsmyArray[1] | returns "Doe" | myArray[5] | returns true | myArray[6] | returns undefined |
Nested objects and arraysvar 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 elementsmyObject.ref.first | returns 0 | myObject.jdoe1 | returns [ "John", "Doe", 39 ... ] | myObject[2] | returns [ "Jane", "Smith", 42 ... ] | myObject.jsmith1[3] | returns "female" | myObject[1][5] | returns true | myObject.jdoe1[myObject.ref.last] | returns "Doe" | myObject.jsmith1[myObject.ref.age] | returns 42 |
|
Created By
Metadata
Favourited By
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
More Cheat Sheets by Mackan90096