JSON Example
This article will have all the JSON Examples which covers each and every data type JSON supports. Here is the list of JSON data types.
Valid JSON Data Types
- String
- Number
- Object
- Array
- Boolean
- Null
1. JSON String Example:
1
2
3
4
5
|
{
"firstname": "Tom",
"lastname": "Cruise",
"occupation": "Actor"
}
|
This example shows information about a person, and you know Tom Cruise. This JSON data represent details which contain the string. Play with JSON String Example. String in JSON has to be in double-quotes.
2. JSON Number Example:
1
2
3
4
5
6
7
8
|
{
"id": 1,
"age": 56,
"bornyear": 1963,
"date": 3,
"month": 7,
"weight" : 67.5
}
|
This example shows how to represent the numbers and I have added the birthday details of Tom Cruise. I have added this in 2018. So you can do the math if this is not 2018. 🙂 Play with JSON Number Example. Numbers in JSON has to be an integer or a floating-point.
3. JSON Object Example:
1
2
3
4
5
6
7
8
9
|
{
"actor": {
"name": "Tom Cruise",
"age": 56,
"Born At": "Syracuse, NY",
"Birthdate": "July 3 1962",
"photo": "https://jsonformatter.org/img/tom-cruise.jpg"
}
}
|
This JSON data represent the detail about the actor and its property. It is a JSON object which can have different properties. Play with JSON Object Example.
4. JSON Array Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
{
"Actors": [
{
"name": "Tom Cruise",
"age": 56,
"Born At": "Syracuse, NY",
"Birthdate": "July 3, 1962",
"photo": "https://jsonformatter.org/img/tom-cruise.jpg"
},
{
"name": "Robert Downey Jr.",
"age": 53,
"Born At": "New York City, NY",
"Birthdate": "April 4, 1965",
"photo": "https://jsonformatter.org/img/Robert-Downey-Jr.jpg"
}
]
}
|
This is an Array of JSON data. It shows two actor objects and each object can have its own properties. Play with JSON Array Example.
5. JSON Boolean Example
1
2
3
4
5
|
{
"hasChildren":true,
"hasTwitterAccount":true,
"hasGreyHair":false
}
|
This JSON Example shows how to represent Boolean values in JSON. Play with JSON Boolean Example. Boolean value has to be true or false.
6. JSON Null Example
JSON Null Example shows how to represent Null values in JSON. Play with JSON Null Example. Null will help to represent value as not available.
I have explained all the Six JSON data types in the above examples.
Example with all the JSON Data Type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
{
"Actors": [
{
"name": "Tom Cruise",
"age": 56,
"Born At": "Syracuse, NY",
"Birthdate": "July 3, 1962",
"photo": "https://jsonformatter.org/img/tom-cruise.jpg",
"wife": null,
"weight": 67.5,
"hasChildren": true,
"hasGreyHair": false,
"children": [
"Suri",
"Isabella Jane",
"Connor"
]
},
{
"name": "Robert Downey Jr.",
"age": 53,
"Born At": "New York City, NY",
"Birthdate": "April 4, 1965",
"photo": "https://jsonformatter.org/img/Robert-Downey-Jr.jpg",
"wife": "Susan Downey",
"weight": 77.1,
"hasChildren": true,
"hasGreyHair": false,
"children": [
"Indio Falconer",
"Avri Roel",
"Exton Elias"
]
}
]
}
|
Play JSON Example with all data types.
I hope this article will help to understand the JSON data. If you want to know more about JSON check out this article. What is JSON?.
Sharing is caring!