✔ JSON stands Form JavaScript Object Notation(JSON), JSON is Text Based Data Format, that is used to store and transfer data,
it is usually useful to sent to data server to webpage,
Syntax of JSON
{
"MoviesStar":[
{"firstName":"John","lastName": "cena"},
{"firstName":"linda","lastName": "Friday"},
{"firstName":"Teresa","lastName": "Plamer"},
]
}
🔴This above JSON Syntax defines movie star name object: an array of 3 moviestar record
⭐In JSON data stored in KEY/VALUE Pair separate by comma,
✨JSON DATA
JSON data is written as name/value pairs, just like JavaScript object Properties, A name and value pair consists of field name(in double qoutes), followed by a colon, followed by value,
e.g "name": "Tony"
JSON Objects
The JSON object is written inside curly braces{}, JSON objects can contain multiple key/value pairs,
for e.g :-
{
"firstName":"Tony",
"lastName": "stark"
}
JOSN Arrays:
JSON array is written inside square Brackets[].
for e.g:-
//JSON array
["audi", "BMW", "jaguar"]
//JSON Array containing objects
[
{"name": "Tony", "age": 48},
{"name": "Peter", "age": 20}
]
🚫Note:
JSON data can contain objects and arrays. However, unlike Javascript objects, JSON data connot contain functions as value.
⭐Accessing JSON data
We can access JSON data using the dot notation LIKE this,
//JSON object
const data = {
"name": "john",
"age": 22,
"hobby": {
"reading": true,
"gamming" false,
"sport": "football"
},
"class":["JavaScript", "HTML", "CSS"]
//accessing JSON object
console.log(data.name); //john
console.log(data.hobby); //{"reading": true,"gamming" false,"sport": "football"}
console.log(data.hobby.sport); //football
console.log(data.class[1]); //HTML
}
Top comments (0)