Introduction
JSON, also known as javascript object notation, is a lightweight, text-based open standard format designed for human-readable data interchange. This format is not dependent on languages, and it is supportable in every type of library, language, and framework.
In this blog, we will see what JSON is, why we use JSON and JSON syntax.
What is JSON
Douglas Crockford initially specified JSON. JSON was standardized as ECMA-404 in 2013. In JSON, we represent data in key-value pairs and hold objects in curly braces, and a colon is followed after every name. We use comma to separate key-value pairs. We use square brackets to hold arrays in which each value is comma-separated.
Features of JSON
- JSON does not depend on language.
- JSON is lightweight.
- JSON is self-describing.
- JSON is known for its simplicity.
- JSON is extensible and interoperable.
Different data types in JSON
Null- It is an empty value.
Boolean- It’s valued can be either true or false;
Example- true.
String- String is written in double quotes. The string can contain numbers, alphanumeric and special characters.
Example- “Hello,” “123”, “xyz_123”.
Number- It represents the numeric value.
Example- 505, 75843838.
JSON object and JSON arrays
JSON object-
{
"state" : "Haryana",
"pincode" : 123,
"developed" : true
}
JSON array-
[
{
"state" : "Haryana",
"cities" : ["Panipat", "Karnal", "Faridabad", "Gurugram"],
},
{
"state" : "Rajasthan",
"cities" : ["Alwar", "Jaipur", "Jodhpur", "Bharatpur"],
}
]