JavaScript Internals (521 Qs)•Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)
What are the syntax rules of JSON
Below are the list of syntax rules of JSON
- The data is in name/value pairs
- The data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
Practical Code Example
javascript
// JSON Syntax Rules:
// 1. Keys must be double-quoted strings
// 2. Values: string, number, object, array, boolean, null (NO functions or undefined)
// 3. No trailing commas allowed
const validJson = `{
"title": "Interview Guide",
"version": 2,
"isActive": true,
"tags": ["js", "frontend"]
}`;
JSON.parse(validJson);