{
"student": {
"name": "Rumaisa Mahoney",
"age": 30,
"fullTime": true,
"languages": ["JavaScript", "HTML", "CSS"],
"GPA": 3.9,
"favoriteSubjects": {"math" : "A", "chemistry" : "C"}
}
}
JSON is used to send information, mostly from backend sources to frontend. Syntax includes, { } which holds objects, property names must be in double quotes "", data is seperated by commas, and [ ] holds arrays.
const jsonStr = '{"bool":true, "num":42}';
const obj = JSON.parse(jsonStr);
console.log(obj.num); // 42
console.log(obj.bool); // true
Turns a JSON string into a JavaScript oject.
const jsObject = {
book: 'JSON Primer',
price: 29.99,
inStock: true,
rating: null
};
const jsonData = JSON.stringify(jsObject);
console.log(jsonData);
Output:
"{
'book':'JSON Primer',
'price':29.99,
'inStock':true,
'rating':null
}"
Converts a JavaScript value into a JSON string.