The Universal Language of Data
JSON (JavaScript Object Notation) is a text-based data format used to exchange data between a client and server. Despite its name, it's supported by virtually every programming language.
JSON Looks Like JavaScript Objects
{
"name": "Alice",
"age": 28,
"isAdmin": false,
"hobbies": ["reading", "coding"],
"address": { "city": "Paris", "zip": "75001" }
}
Working with JSON in JavaScript
Serialize (Object → String) for sending:
const user = { name: 'Alice', age: 28 };
const jsonString = JSON.stringify(user);
// '{"name":"Alice","age":28}'
Deserialize (String → Object) after receiving:
const obj = JSON.parse(jsonString);
console.log(obj.name); // 'Alice'
Pretty-print for debugging:
console.log(JSON.stringify(user, null, 2)); // indent with 2 spaces
Caution
JSON does NOT support functions, undefined, Date objects (stored as strings), or circular references. When you stringify an object, all its methods are silently dropped.