Course contentsShow
← JavaScript
Lesson 678 of 2,72316. Object Methods and PatternsFree lesson

JSON Syntax Rules

Learning the strict syntax requirements: double quotes, no trailing commas, limited types, and no functions.

JSON Syntax Rules

You'll learn the strict formatting requirements that make JSON valid and universally parsable.

Why JSON Is So Strict

JSON (JavaScript Object Notation) is designed to be a universal data exchange format that works across all programming languages. To achieve this, JSON enforces much stricter syntax rules than JavaScript object literals. Think of it like the difference between casual conversation (JavaScript objects) and a formal legal document (JSON)—the legal document needs precise, unambiguous formatting so everyone interprets it exactly the same way.

The Core Rules

1. Double Quotes Only

Property names and string values must use double quotes ("). Single quotes aren't allowed.

2. No Trailing Commas

You cannot have a comma after the last property in an object or last element in an array. JSON parsers will reject it.

3. Limited Data Types

JSON supports only: strings, numbers, booleans (true/false), null, arrays, and objects. No undefined, no NaN, no Infinity.

4. No Functions or Methods

JSON is pure data. You cannot store functions, methods, dates (as Date objects), or any executable code.

5. No Comments

JSON has no comment syntax. Every line must be valid data structure.

Why These Rules Matter

When you convert JavaScript objects to JSON for storage or transmission, these rules ensure the receiving system—whether it's a server, database, or browser—can reliably reconstruct your data. The strict syntax prevents ambiguity and parsing errors.

Key Takeaway: JSON syntax is stricter than JavaScript object literals—it requires double quotes, no trailing commas, only basic data types (no functions or undefined), and no comments.