Web Technology - Old Questions
7. What is the use of JSON? How can you parse a JSON, illustrate with an example.[1+4]
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).
Structure:
Example:
{
"name": "Archana",
"age": 22
}
The JSON.parse()
method parses a JSON string, constructing the JavaScript value or object described by the string.
Syntax: JSON.parse(text);
- text is the string to parse as JSON.
Example:
const json = '{"name":"Archana, "age":22}';
const obj = JSON.parse(json);
console.log(obj.name); // expected output: Archana
console.log(obj.age); // expected output: 22