JSON (JavaScript Object Notation) is the standard format for exchanging data between systems — APIs, config files, local storage. It looks like a JavaScript object literal but with stricter rules.
undefined, or comments.{
"name": "Alice",
"age": 30,
"skills": ["JavaScript", "HTML"],
"address": { "city": "London" }
}
JSON.stringify() — object → stringconst user = { name: "Alice", age: 30 };
const json = JSON.stringify(user);
console.log(json); // '{"name":"Alice","age":30}'
console.log(typeof json); // "string"
// Pretty-print with 2-space indent
JSON.stringify(user, null, 2);
JSON.parse() — string → objectconst data = '{"name":"Bob","score":95}';
const obj = JSON.parse(data);
console.log(obj.name); // "Bob"
console.log(obj.score); // 95
user = { name: "Sam", level: 5, active: true }, serialize it to a JSON string and store in userJson.apiResponse = '{"status":"ok","count":42}' and store the result in parsed.deepClone(obj) that uses JSON serialization to create a deep copy of an object.#output: "Sam is level 5 | status: ok, count: 42".Use JSON.stringify(obj) to convert an object to a JSON string.