JSON Fun Facts

  • Origin: Douglas Crockford discovered JSON in 2001—he says he 'didn't invent it, just found it'
  • Name: JavaScript Object Notation, but used by every language now (Python, Go, Rust, Java...)
  • File size: Minified JSON is ~30% smaller than formatted—matters for APIs serving millions of requests

Top JSON Mistakes (And How to Spot Them)

  • Trailing comma: {"a": 1,} ← Remove that last comma! Valid in JS, invalid in JSON
  • Single quotes: {'name': 'John'} ← Must use double quotes for keys AND strings
  • Unquoted keys: {name: "John"} ← Every key needs double quotes
  • Comments: // not allowed ← JSON has no comments (use JSONC formatter for that)
  • Undefined: undefined isn't valid—use null instead

JSON vs Similar Formats

  • JSON5: Allows comments, trailing commas, unquoted keys—human-friendly JSON
  • JSONC: JSON with Comments—used by VS Code, TypeScript configs
  • YAML: Indentation-based, more readable for configs, but whitespace-sensitive
  • TOML: INI-like format, popular in Rust (Cargo.toml) and Python (pyproject.toml)

Real-World Debugging

  • API returns HTML instead of JSON? Check if you're hitting an error page or wrong endpoint
  • "Unexpected token < at position 0" = Server returned HTML (probably a 404 or 500 page)
  • Nested escape hell? {"data": "{\"nested\": true}"} = JSON stringified twice
  • Unicode issues? Ensure UTF-8 encoding and escape special chars (\u0000 format)
  • Large files slow? Streaming parsers (like JSONStream) handle gigabyte files

Size Matters: JSON Compression

  • Minify first: Removes whitespace (30% smaller, free)
  • GZIP: Standard HTTP compression (70-90% smaller)
  • Short keys: {"n": "John"} vs {"firstName": "John"} saves bytes at scale
  • Arrays over objects: [{"id":1},{"id":2}] → [1,2] when context is clear
  • Binary alternatives: Protocol Buffers, MessagePack for performance-critical apps

Pro Developer Workflow

  • Pipe curl to jq: curl api.example.com | jq '.' for instant formatting
  • VS Code: Ctrl+Shift+I formats JSON in place (with a formatting extension)
  • Chrome DevTools: Network tab → Response → Pretty Print button
  • Bookmark this tool: Paste sensitive API responses here—nothing leaves your browser