Getting Started
Introduction
JSON is a lightweight text-based open standard designed for human-readable data interchange.
- JSON stands for JavaScript Object Notation
- JSON is easy to read and write.
- JSON is language agnostic data-interchange format
- JSON filename extension is
.json
- JSON Internet Media type is
application/json
{.marker-round}
Examples
Types
| Type |
Description |
Number |
Double precision floating-point |
String |
Series of characters |
Boolean |
true or false |
Array |
Ordered sequence of values |
Value |
String, Number, Boolean, null etc |
Object |
Unordered collection of key/value pairs |
null |
Null or Empty |
String
|
|
\" |
Double quote |
\\ |
Backslash |
\/ |
Forward slash |
\b |
Backspace |
\f |
Form feed |
\n |
Newline |
\r |
Carriage return |
\t |
Tab |
\u |
Trailed by four hex digits |
Examples
Invalid String
Have to be delimited by double quotes
Number
| Type |
Description |
Integer |
Digits 1-9, 0 and positive or negative |
Fraction |
Fractions like 0.3, 3.9 |
Exponent |
Exponent like e, e+, e-, E, E+, E |
Examples
Invalid Number
In JSON you can use only Decimal Literals
Objects
Multiple key/value pairs separated by a comma
Arrays
Begins with [ and ends with ]
Array of objects
Object of arrays
2D Array
Object of objects
Nested
Access JSON in JavaScript
Access Object
|
|
myObject.name |
“Jason” |
myObject["name"] |
“Jason” |
myObject.age |
39 |
myObject.other |
undefined |
myObject[0] |
undefined |
Access Nested
|
|
myObject.ref.age |
2 |
myObject["ref"]["age"] |
2 |
myObject.jdoe |
[“Jason”, “Doe”, 39 …] |
myObject.jsmith[3] |
“F” |
myObject[1] |
undefined |
Access Array of Objects
|
|
myArray[0] |
{“name”: “Jason”, …} |
myArray[1].name |
“Tom” |
myArray[1][2] |
42 |
myArray[3] |
undefined |
myArray[3].gender |
TypeError: Cannot read… |
Access Array
|
|
myArray[1] |
“Doe” |
myArray[5] |
true |
myArray[6] |
undefined |
Also see