JSON
01 / 06

JSON Syntax & Data Types

JSON Syntax & Data Types

JSON (JavaScript Object Notation) is a text-based data format. It has exactly 6 value types and strict syntax rules.

The 6 Value Types

  • string — always double quotes: "hello"

  • number — integer or float, no quotes: 42, 3.14, -7, 1e10

  • boolean — lowercase only: true, false

  • null — lowercase only: null

  • object — key/value pairs: { "key": value }

  • array — ordered list: [1, "two", null]

Valid JSON Examples

// Object
{
  "name": "Alice",
  "age": 30,
  "active": true,
  "score": 9.5,
  "address": null,
  "tags": ["admin", "user"],
  "meta": { "created": "2024-01-01" }
}

// Array at root level — also valid JSON
[1, 2, 3]

// Primitive at root level — also valid
"hello"
42
true

Common Syntax Mistakes

// ❌ Trailing comma
{ "a": 1, }

// ❌ Single quotes
{ 'key': 'value' }

// ❌ Unquoted keys
{ key: "value" }

// ❌ Comments (not valid in JSON)
{ "x": 1 // this is x }

// ❌ undefined is not a JSON value
{ "x": undefined }

// ✅ Use null instead
{ "x": null }

Key Rules

  • Keys must be strings wrapped in double quotes

  • No trailing commas — JSON parsers are strict

  • No comments — use a wrapper format like JSONC if you need them

  • String values must escape: \" \\ \/ \b \f \n \r \t \uXXXX

  • Numbers must not have leading zeros: 01 is invalid

  • Whitespace (spaces, tabs, newlines) is ignored outside strings

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free