{
"Jack": {
"id": 1,
"name": "Franc",
"salary": 25000,
"hobby": ["a", "b"],
"location": {
"country": "A", "city": "A-A"
}
}
}
Getting Started
Nested
Object of objects
{
"Mark McGwire": {
"hr": 65,
"avg": 0.278
},
"Sammy Sosa": {
"hr": 63,
"avg": 0.288
}
}
2D Array
{
"my\_sequences": [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9, 0],
[10, 11]
]
}
Object of arrays
{
"attributes": ["a1", "a2"],
"methods": ["getter", "setter"],
"empty\_array": []
}
Array of objects
{
"children": [
{"name": "Jimmy Smith", "age": 15},
{"name": "Sammy Sosa", "age": 12}
]
}
Arrays
[1, 2, 3, 4, 5]
Begins with [
and ends with ]
Objects
{
"color": "Purple",
"id": "210",
"composition": {
"R": 70,
"G": 39,
"B": 89
},
"empty\_object": {}
}
Multiple key/value pairs separated by a comma
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
{
"positive" : 12,
"negative" : -1,
"fraction" : 10.25,
"exponent" : 1.0E+2,
"zero" : 0
}
#Invalid Number
{ "foo": 0xFF }
In JSON you can use only Decimal Literals
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
{
"url": "https://quickref.me",
"msg" : "Hi,\n\"QuickRef.ME\"",
"intro": "Share quick reference and cheat sheet for developers."
}
#Invalid String
{ "foo": 'bar' }
Have to be delimited by double quotes
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 |
Examples
{
"name": "Jason",
"age": 39,
"height": 1.92,
"gender": "M",
"salary": 70000,
"married": true,
"children": [
{"name": "Tom", "age": 9, "gender":"M"},
{"name": "Ava", "age": 7, "gender":"F"}
]
}
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
Comments