What are JSON structures?

JSON ( JavaScript Object Notation ) is a lightweight text-based language. The data can only be text while it is being exchanged between a browser and a server. Any JavaScript object can be converted into a JSON text.

Data structures in JSON

JSON supports these two data structures:

svg viewer

A JSON can store several types of values, listed in the table below:

Values Description
String In JSON, strings are enclosed in double quotes and there are many special characters like b (backspace), t (tab), etc.
Number JSON supports different number types like integer, fraction and exponential.
Boolean In JSON, true or false value can also be assigned.
Null In JSON, an empty value can be assigned.
svg viewer

Collection of key-value pairs

Here, key-value pairs are always placed between curly brackets ({ }). If there is more than one key-value pair, they are separated by commas.

An ordered list of values

Here, values are enclosed in square brackets ([ ])and each value is separated by a comma…

svg viewer
svg viewer
{
"Students" : [
{
"name" : "Aaron",
"subject" : "Data structures",
"age" : 19
},
{
"name" : "Beck",
"subject" : "Algorithms",
"age" : 23
},
{
"name" : "David",
"subject" : "Machine Learning",
"age" : 28
}
]
}

Note that in the above code snippet, there is an array of Students objects.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved