JSON Array & JSON Object
JavaScript Object Notation it is structured, light-weight, readable and easy to parse.
What is JSON?
JSON stands for JavaScript Object Notation. It’s a lightweight data interchange format inspired by JavaScript object syntax. JSON is easy for humans to read and write, and it’s also easy for machines to parse and generate. JSON is perfect for data transmission between a web application and a server since it is text-based. Most modern programming languages have built-in or third-part libraries to parse and generate JSON data.
JSON data is represented as key-value pairs, similar to how objects are represented in JavaScript. Keys are always strings and values can be of following data types-
- String
- Number- Numerical values
- Arrays — Associative array of just values
- Object — An associative array of key-value pairs
- Boolean — True or False
JSON Array
JSON Arrays are very similar to arrays in JavaScript. A JSON array is ordered collection of values enclosed within square brackets ‘[ ]’.
Each value in JSON array can be any JSON data type -
- string
- number
- array
- boolean
- null
Values in JSON array are indexed stating from 0.
Get Harshada Wayal’s stories in your inbox
Join Medium for free to get updates from this writer.
Example -
["Toyota", "Baleno", "Brezza"]Another mixed data type Example -
[4, true, "Baleno", {"name": "Martin", "age": 25}]JSON Object
A JSON object is an unordered collection of key-value pairs enclosed within curly braces ‘{ }’. Each key in JSON object must be a string, and it must be unique within that object.
The values associated with keys in a JSON object can be of any valid JSON data type -
- string
- number
- object
- array
- boolean
- null
Example of JSON Object -
An example here is Student object.
{
"name": "Noah",
"age" : 21,
"city":"London"
}Another example with nested objects-
{
"name":"Henry",
"age": 22,
"address": {
"street":"Square main st",
"city": "London",
"zip": "10001"
}
}Combining JSON Array And JSON Object
- JSON Array and objects can be nested within each other to represent complex data structures.
- Example- JSON object containing JSON array
{
"user":[
{
"id": 1,
"name": "Sachin",
"gender":"male",
"age": 22,
}
{
"id": 3,
"name": "Neha",
"gender":"female",
"age": 22,
}
]
}




