JSON basics

The shape of JSON, how it maps to language types, and the easy mistakes that produce invalid JSON.

The JSON type system

JSON (JavaScript Object Notation) is a text format for structured data built from just two containers β€” objects {} and arrays [] β€” and a small set of scalar values: string, number, boolean, null.

JSONJavaScriptPython
objectObjectdict
arrayArraylist
stringStringstr
numberNumberint / float
true/falsebooleanbool
nullnullNone

Rules that break parsers

⚠️
JSON is not JavaScript. {a: 1} is valid JS but invalid JSON β€” the key needs quotes. This is the #1 cause of parse errors.
{
  "name": "Ada",
  "age": 36,
  "skills": ["math", "logic"],
  "active": true,
  "score": null
}

Reading and writing it

// Parse (throws on invalid JSON)
const obj = JSON.parse(text);

// Serialize (replacer + indent for readability)
const text = JSON.stringify(obj, null, 2);
import json
obj = json.loads(text)        # parse
text = json.dumps(obj, indent=2)  # pretty-print

FAQ

What is the difference between JSON and a JS object?
JSON is a string format with stricter rules (quoted keys, no functions/comments). A JS object is an in-memory value.
How do I pretty-print minified JSON?
json.dumps(json.loads(text), indent=2) in Python, or JSON.stringify(obj, null, 2) in JS.

CSV vs JSON UTF-8 and character sets

Last refreshed 2026-09-17.