The artist profile may need to travel as text between programs. Turn an object into JSON text, parse a response, and compare a copy with its original in the Console.
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 recipe = { dish: "Soup", servings: 4 };
const recipeText = JSON.stringify(recipe);
const weather = JSON.parse("{\"condition\":\"clear\",\"temp\":19}");
console.log(recipeText, weather.condition);
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) using JSON.parse(JSON.stringify(obj)) for JSON-safe data only; functions, undefined, Date, and BigInt are not preserved.nested.b to 99, leaving the original unchanged.Sam is level 5 | status: ok, count: 42 on its own Console line.Use JSON.stringify(obj) to convert an object to a JSON string.
Use JSON.parse(str) to convert a JSON string back to an object.
JSON.stringify accepts a second argument (replacer) and third (indent spaces).