What JSON is
JSON (JavaScript Object Notation) is a text-based data format derived from a subset of JavaScript object literal syntax. It was popularized by Douglas Crockford in the early 2000s and standardized as ECMA-404 and RFC 8259. JSON is the default data interchange format for almost every modern API because it is human-readable, language-agnostic, and trivial to parse.
The JSON data model
JSON has exactly six value types:
- Object — an unordered collection of key/value pairs, surrounded by
{}. Keys must be strings. - Array — an ordered list of values, surrounded by
[]. - String — UTF-8 text in double quotes. Single quotes are not valid JSON.
- Number — base-10 integer or float. No leading zeros, no NaN, no Infinity.
- Boolean — lowercase
trueorfalse. - Null — lowercase
null.
There is no date type, no binary type, no comment syntax, and no integer/float distinction at the wire level. JavaScript's undefined is also not valid JSON.
Pretty-print vs minify
The same JSON document can be written compactly or expanded with whitespace — both are valid and parse to the same data. Pretty-printing makes data easier to read and review; minifying saves bandwidth in production responses.
- Minified — no extra whitespace:
{"a":1,"b":[2,3]}. Smallest, hardest to read. - Pretty (2-space) — most readable for short documents, the most common style in code review and documentation.
- Pretty (4-space or tab) — friendlier for deeply nested structures.
Object keys in pretty-printed JSON are conventionally not sorted, but sorting alphabetically can help diff tools detect real changes versus reordering.
Common JSON mistakes
- Trailing commas:
{"a": 1,}is invalid. JavaScript and JSON5 allow them; standard JSON does not. - Single quotes: JSON requires double quotes for both keys and string values.
- Unquoted keys: JavaScript permits
{a: 1}; JSON requires{"a": 1}. - Comments: standard JSON has none. If you need them, use JSON5 or YAML, or strip comments before parsing.
- Leading zeros on numbers:
007is invalid. Use7or quote it as a string. - NaN, Infinity, undefined: not valid in JSON. Convert to null, a string, or omit the field.
Integer precision and big numbers
JSON itself has no precision limit on numbers, but JavaScript parses numbers as 64-bit floats, which can only represent integers exactly up to 2⁵³ − 1 (about 9.007 × 10¹⁵). API responses that include 64-bit IDs (Twitter, Discord, database row IDs in many systems) will silently lose precision in JavaScript. The standard workaround is to serialize large integers as strings, then handle them with BigInt on the JavaScript side.
JSON dialects you may encounter
- JSON5 — allows comments, trailing commas, unquoted keys, single quotes. Used in configuration files. Not interchangeable with strict JSON over the wire.
- JSONC — JSON with comments only. Used by VS Code config and TypeScript
tsconfig.json. - NDJSON / JSON Lines — one JSON object per line, no surrounding array. Useful for streaming and append-only logs.
- BSON — binary JSON used by MongoDB. Adds date, ObjectId, and binary types.
- Smile, MessagePack, CBOR — binary alternatives, ~30–50% smaller, faster to parse.
Validating and formatting safely
Before pasting JSON into a public tool, remember that the formatter sees everything. For sensitive payloads (auth tokens, PII), prefer a fully client-side tool — this one runs entirely in your browser. To validate JSON programmatically:
- JavaScript:
JSON.parse()throws on invalid input. - Python:
json.loads()raisesjson.JSONDecodeError. - Schema validation: use JSON Schema (Ajv, jsonschema) to validate structure beyond just syntax.
- Linting:
jq empty file.jsonvalidates and is the simplest CLI option.