JSON (JavaScript Object Notation) is a lightweight data interchange format that is widely used for transmitting data between a server and a web application, as well as for storing data. It is a text-based format that is easy for both humans and machines to read and write. JSON is based on JavaScript object literal syntax, but it is language-independent and can be parsed and generated by many programming languages. Here are some key aspects of JSON:
JSON syntax is similar to JavaScript object literal syntax. It consists of key-value pairs enclosed in curly braces {} , with each key and value separated by a colon : . Multiple key-value pairs are separated by commas.
{
"name": "John",
"age": 30,
"isStudent": false,
"address": {
"street": "123 Main St",
"city": "New York"
},
"hobbies": ["reading", "traveling", "photography"]
}
JSON supports several data types:
const jsonData = '{"name":"John","age":30,"isStudent":false}';
const jsonObject = JSON.parse(jsonData);
console.log(jsonObject.name); // Output: John
const personObject = { name: 'Alice', age: 25, isStudent: true };
const jsonString = JSON.stringify(personObject);
console.log(jsonString); // Output: {"name":"Alice","age":25,"isStudent":true}
JSON is commonly used for:
JSON's simplicity, readability, and language independence make it a popular choice for data interchange in web development and beyond. It has become a de facto standard for transmitting structured data over the internet.