Learn Guide

JSON Basics

Learn the universal data format used in every web API.

What is JSON?

JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging structured data. It is the dominant format for web APIs and configuration files.

{
  "name": "Alice",
  "age": 30,
  "active": true,
  "tags": ["developer", "designer"]
}

Data Types

JSON supports exactly 6 value types — nothing more, nothing less.

Type Example Notes
String "hello" Always double-quoted
Number 42, 3.14 No quotes, no NaN/Infinity
Boolean true, false Lowercase only
Null null Represents absence of value
Array [1, "a", true] Ordered, mixed types allowed
Object {"key": "val"} Unordered key-value pairs

Syntax Rules

  • Keys must be double-quoted strings
  • No trailing commas after the last property
  • No comments — JSON has no comment syntax
  • Strings use double quotes only — not single quotes
{ 'name': 'Alice', age: 30, }

❌ Invalid — single quotes, unquoted key, trailing comma.

{ "name": "Alice", "age": 30 }

✅ Valid.

Common Mistakes

Trailing comma — the most common parsing error:

{ "name": "Alice", }   // ❌
{ "name": "Alice" }    // ✅

Undefined / NaN — these don't exist in JSON. Use null instead:

{ "value": undefined }  // ❌
{ "value": null }       // ✅

Numeric string vs number"42" and 42 are different types. Only use numbers for arithmetic.