JSON guide: syntax, data types, and common errors

A quick, practical reference for reading and writing valid JSON.

What is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based format for storing and exchanging structured data. It is language-independent and is the default data format for most web APIs and many configuration files. A JSON document is always a single value — most often an object or an array.

The six data types

  • String — double-quoted Unicode text, e.g. "hello".
  • Number — integer or decimal, e.g. 42 or 3.14. No leading zeros, and no NaN or Infinity.
  • Booleantrue or false (lowercase).
  • Nullnull.
  • Array — an ordered list in square brackets, e.g. [1, 2, 3].
  • Object — unordered key/value pairs in curly braces, e.g. { "id": 1 }.

Syntax rules

  • Object keys must be double-quoted strings.
  • Use double quotes, never single quotes.
  • Separate items with commas, but never leave a trailing comma after the last item.
  • Comments are not allowed in standard JSON.
  • Whitespace between tokens is ignored, so indentation is free.

Common errors and how to fix them

  • Trailing comma — remove the comma after the last array element or object property.
  • Single quotes — replace 'text' with "text".
  • Unquoted keys — wrap keys in double quotes: { name: 1 } becomes { "name": 1 }.
  • Missing commas — add a comma between items.
  • Comments — remove // or /* */; use JSONC/JSON5 tooling if you need them.

Paste any of these into the JSON validator to see exactly where parsing fails.

JSON vs YAML, CSV, and XML

JSON is machine-friendly and nestable. YAML is more human-readable and supports comments, which makes it popular for configuration. CSV is ideal for flat, tabular data and spreadsheets. XML is verbose but still common in legacy and enterprise systems. Use the converters to move between them: JSON to YAML, JSON to CSV, and JSON to XML.

Tips for working with large JSON

  • Pretty-print to read it; compact to ship it.
  • Validate before sending to an API so you catch typos early.
  • Integers larger than 253 can lose precision in JavaScript — transmit them as strings.

Head back to the JSON formatter to try these out.