What is JSON in JavaScript?
Answer
JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write and for machines to parse. Despite its name, JSON is language-independent and used across all programming languages. JSON supports: objects ({}), arrays ([]), strings (double quotes only), numbers, booleans (true/false), and null. Serialize (JS object → JSON string): JSON.stringify(obj). Pretty print: JSON.stringify(obj, null, 2). Parse (JSON string → JS object): JSON.parse(jsonString). Both can throw errors — wrap in try/catch. JSON.stringify ignores: functions, undefined, Symbol-keyed properties. Replace values during serialization with the second argument (replacer function/array). Common use: API communication, localStorage, configuration files.