What JSON is and why developers use it
JSON (JavaScript Object Notation) is a text format for structured data built from objects, arrays, strings, numbers, booleans, and null. Although the name references JavaScript, JSON is language-neutral: Python, Go, Java, C#, PHP, and Rust all ship standard libraries to read and write it. REST APIs, mobile apps, serverless configuration, and CI/CD pipelines depend on JSON because it is compact, human-readable when formatted, and universally supported.
The authoritative rules live in RFC 8259 (which obsoletes RFC 7159). RFC 8259 defines the grammar: objects use curly braces with comma-separated "key": value pairs; arrays use square brackets; strings must use double quotes; numbers follow decimal notation; and only true, false, and null are valid literals besides strings and numbers. UTF-8 is the default encoding. A single stray comma or quote type causes strict parsers to reject the entire file.
Validation vs formatting: two different jobs
Validation answers one question: is this text legal JSON? A validator parses the input and reports the first syntax error—often with a position hint—without changing the payload. That is what you need before committing a package.json, infrastructure export, or API fixture to source control.
Formatting (pretty-printing) assumes the text already parses. It re-serializes the structure with consistent indentation (this tool uses two spaces) so you can review nested objects or paste readable samples into documentation. Formatting does not fix invalid JSON. Minification removes non-essential whitespace to shrink production HTTP responses or bundled config files. Use validate → format while debugging, then minify before shipping when byte size matters.
Common syntax errors (and how to spot them)
- Trailing commas: JSON does not allow a comma after the last element (
{"a": 1,}is invalid). JavaScript tolerates this; JSON does not. - Unquoted keys: Keys must be double-quoted strings (
{name: "Ada"}fails;{"name": "Ada"}works). - Single-quoted strings: Only double quotes delimit strings. They appear often when JSON is copied from SQL or Python dicts.
- Comments:
//and/* */are not part of JSON. Strip comments before validating here. - Undefined / NaN / Infinity: These JavaScript values have no JSON equivalent. Export tools must omit them or map them to
null. - Mismatched brackets: One missing
]or}breaks the whole document; formatting after a small edit often reveals where nesting went wrong.
Paste the failing snippet into the validator above: the error message usually points to the unexpected token, which maps back to the character position in your textarea.
Practical workflows
API debugging: Network tabs and logs often show minified one-line responses. Copy the body, format it, then trace fields before updating client code. Configuration review: IAM policies, Firebase rules, and CI matrices frequently export JSON; pretty-printing speeds policy review. Data migration: Validate an intermediate JSON export before overnight import jobs. Code review: Formatted JSON in pull requests helps reviewers see schema changes, especially renamed nested keys.
This formatter runs entirely in your browser: nothing is uploaded to our servers. For related tools, try the YAML formatter, the XML formatter, or the code minifier. See also our CI/CD developer guide, the code formatters blog guide and the full formatters directory.
RFC 8259 quick reference
| Type | Example | Notes |
|---|---|---|
| Object | {"id": 1, "active": true} | Keys are strings. |
| Array | [1, 2, 3] | Mixed types allowed. |
| String | "hello\n" | Standard escape sequences apply. |
| Number | -42, 3.14, 1e6 | No NaN or Infinity. |
| Boolean | true, false | Lowercase only. |
| Null | null | Intentional absence of value. |
After formatting, run Validate before sharing externally. Use Minify only when the structure is confirmed—minified files are harder to eyeball for mistakes.