JSON (JavaScript Object Notation) is the lingua franca of modern APIs. It is the format your server returns from REST endpoints, the structure configuration files use, and the payload webhooks deliver. When it is malformed, everything breaks often with a cryptic parse error. Format and validate any JSON string instantly with the JSON Formatter.
JSON Syntax Rules
JSON has strict syntax requirements that XML and YAML do not:
- Strings must use double quotes single quotes are invalid
- No trailing commas
{"a":1,}is invalid JSON - No comments JSON has no comment syntax (use JSONC for commented configs)
- Keys must be strings numeric keys are not valid in JSON objects
- No undefined, NaN, or Infinity these JavaScript values have no JSON equivalent
- Root element must be object or array a bare string or number at root is technically valid per RFC 8259 but many parsers reject it
Common JSON Errors and How to Fix Them
Unexpected token
Usually caused by a single quote instead of double quote, a trailing comma, or a missing colon between key and value. The JSON Formatter highlights the exact line and character where the error occurs.
Circular reference
JSON cannot serialise circular object references. In JavaScript, JSON.stringify() throws "Converting circular structure to JSON". Use a library like flatted or remove circular references before serialising.
Unicode escape sequences
JSON supports Unicode escapes (\uXXXX). Characters outside the Basic Multilingual Plane (like emoji) require surrogate pairs. Most modern parsers handle UTF-8 directly prefer UTF-8 encoded strings over escape sequences for readability.
JSON vs YAML vs XML
JSON is not always the best choice:
- YAML more human-readable for configuration files, supports comments, but has significant whitespace sensitivity and YAML bombs risk
- XML superior for document-centric data with mixed content; required by some legacy APIs and SOAP services
- JSON best for API communication, lightweight configuration, and anywhere JavaScript is the consuming language
See the official JSON specification and RFC 8259 for the authoritative grammar.
Frequently Asked Questions
How do I pretty-print JSON in the terminal?
Use Python: cat file.json | python3 -m json.tool. Or with jq: cat file.json | jq .. jq also supports filtering and transformation. For browser-based formatting without installing anything, the JSON Formatter handles any valid JSON string.
What is the maximum size of a valid JSON file?
The JSON specification sets no limit. Practical limits are imposed by the parser (memory) and the transport layer. Many browsers limit JSON parsing to ~500 MB before running out of call stack or heap. For large data sets, consider streaming parsers or binary formats like Protocol Buffers.
Is JSON case-sensitive?
Yes. {"Name":"John"} and {"name":"John"} are different keys. This is a common source of bugs when integrating with APIs that use inconsistent casing always check the exact key names in the API documentation. The MDN JSON documentation covers the full JavaScript API.