Question presented to candidate: "What is JSON, and why do you think it became the default format for APIs and config files instead of just sending native language objects?"
What a strong answer should cover:
- JSON (JavaScript Object Notation) is a lightweight, text-based data format for exchanging structured data, and despite the name it is language-independent -- Python, Java, Go, and every other mainstream language can read and write it.
- JSON supports exactly six kinds of values: objects, arrays, strings, numbers, booleans, and null -- notably no functions, no undefined, no Date, no Map or Set, no BigInt.
- JSON.stringify() serializes a JS value into a JSON string; JSON.parse() does the reverse; both accept an optional second argument (a replacer function/array, or a reviver function) for filtering or transforming values during the conversion.
- JSON is stricter than a JavaScript object literal -- unquoted keys and trailing commas are both syntax errors to JSON.parse(), even though they would be perfectly valid inside real JS source code.
- Real lossy edges worth naming unprompted: functions and undefined properties are dropped, Date becomes a plain ISO string (not restored as a Date on parse), Map and Set serialize to an empty object, BigInt throws, and a circular reference throws a TypeError.
Clarifying questions expected:
- "Do you want me to also cover structuredClone as a modern alternative for deep cloning, or keep this focused on JSON itself?"
Code / implementation expected: Yes -- a short, runnable snippet demonstrating stringify/parse and the lossy edges.