Three. Two.
Online
JSON
Cheat Sheet
</>
JSON Cheat Sheet 1
Start your own website with unlimited hosting.
Use HostingerTutorials discount code and USE IT TODAY
get up to 83% OFF for any web hosting plan.
JSON Cheat Sheet
JSON Syntax
The JSON syntax is largely a subset of the JavaScript syntax. Here are its core components:
Key/value pairs represent data.
Data is separated by commas.
Curly brackets {} represent objects.
Square brackets [] delineate arrays.
Therefore, JSON syntax looks like this:
{“key”:“value”,“key”:“value”,“key”:“value”.}
Types of Values
There are six kinds of values in JSON.
1 Arrays
An array is an ordered list of values that are surrounded by square brackets,
each separated by a comma. For example:
[
{"firstName":"Jack", "lastName":"Smith"},
{"firstName":"Jane", "lastName":"Perkins"},
{"firstName":"Richard", "lastName":"Kilmer"}
]
2 Objects
An object contains a key and value separated by a colon. There is a comma after
every pair. All elements are inside sets of quotation marks. For example:
{
"spouse":{
"firstName":"John",
"lastName":"Smith"
}
}
HOSTINGER Three. Two. Online
JSON Cheat Sheet 2
3 Strings
A string is a set of sequences of zero or more Unicode characters with double
quotation marks enclosing them. For example:
{"city":"London"}
4 Numbers
A number contains either an integer or a floating point. For example:
{“age”:45}
5 Boolean
A boolean contains true or false as values. For example:
{“active”:true)
6 Null
This value shows that there is no information. For example:
your web content should be easy to perceive for any visitor.
{"middleName":null}
Coding with JSON
Here is an example of JSON data:
{
Here’s what each pair indicates:
"name":"Jennifer",
"age":39, "name":"Jada" is a string.
"religion":null, "age":39 is a numeric value.
"married":true, "religion":null represents a null.
"spouse":{"firstName":"John", "lastName":"Smith"}, "married":true is a boolean.
"children":[{ "spouse":{"firstName":"John",
"firstName":"Jackson","lastName":"Smith"}, "lastName":"Smith"} is an object literal.
{"firstName":"Jackie","lastName":"Smith"}, An array is represented from the sixth
{"firstName":"Jacob","lastName":"Smith"}, line onwards.
{"firstName":"Jacinda","lastName":"Smith"},
]
}
HOSTINGER Three. Two. Online