JSON (JavaScript Object Notation) is the universal standard data interchange format of the global software industry. Derived from JavaScript object literal syntax, JSON is strictly text-based and completely language-agnostic, easily parsed by Python, PHP, Java, C#, and Go.
"name": "Vikram" (Single quotes or unquoted keys are invalid!)."title", never 'title'.[1, 2, 3,] is an invalid JSON syntax error.null.JSON.stringify(value, replacer, space) - Serializationconst student = {
id: 101,
name: "Vikram",
enrolled: true,
hobbies: ["chess", "coding"],
secretToken: "xyz123" // Sensitive
};
// 1. Basic Serialization
const jsonString = JSON.stringify(student);
console.log(jsonString); // '{"id":101,"name":"Vikram","enrolled":true,"hobbies":["chess","coding"],"secretToken":"xyz123"}'
// 2. Formatted Pretty-Print with 2 spaces indentation:
const prettyJSON = JSON.stringify(student, null, 2);
// 3. Using Replacer Function to filter out sensitive keys:
const safeJSON = JSON.stringify(student, (key, val) => {
if (key === "secretToken") return undefined; // Strips key!
return val;
});
console.log(safeJSON); // secretToken is completely omitted!
JSON.parse(text, reviver) - Deserializationconst incomingPayload = '{"title":"BCA Syllabus","publishDate":"2026-11-05T08:00:00.000Z"}';
// Using a Reviver function to automatically reconstruct Date objects:
const parsedData = JSON.parse(incomingPayload, (key, value) => {
if (key === "publishDate") return new Date(value);
return value;
});
console.log(parsedData.publishDate instanceof Date); // true!
Exam Trap: "What error occurs when running JSON.stringify() on an object with circular references?"
Answer: It throws TypeError: Converting circular structure to JSON.
Example: let a = {}; a.self = a; JSON.stringify(a);
The serializer enters an infinite loop trying to serialize 'a' inside itself and throws a TypeError.
Congratulations on completing Tier 5: Asynchronous Programming & APIs! Now let us dive into the deepest engine internals of JavaScript. Proceed to Tier 6: JavaScript Execution Context & Hoisting Internals →