Format, validate, and debug JSON instantly with WOWHOW's free online JSON formatter. Covers syntax errors, nested objects, arrays, and common JSON pitfalls.
A single trailing comma in a JSON payload can bring down a production API endpoint — and JSON's spec forbids trailing commas entirely.
JSON (JavaScript Object Notation) has become the universal data interchange format. REST APIs, configuration files, database documents, GraphQL responses, webhook payloads — all JSON. But JSON is deceptively strict. JavaScript, the language it was derived from, accepts trailing commas, single quotes, and comments. JSON accepts none of them. The gap between what developers expect and what the spec allows causes a disproportionate share of integration bugs.
This guide covers JSON formatting, validation, common syntax errors, and how to use the free WOWHOW JSON formatter and validator to debug payloads before they hit your API.
JSON Syntax: The Complete Rules
JSON has exactly six value types: strings, numbers, objects, arrays, booleans (true/false), and null. Everything else is invalid. Understanding these rules prevents 90% of JSON syntax errors before they occur.
Strings
JSON strings must use double quotes — not single quotes, not backticks, not unquoted identifiers. Any of the following are invalid JSON strings:
// INVALID — single quotes
{ 'name': 'Alice' }
// INVALID — unquoted keys
{ name: "Alice" }
// VALID
{ "name": "Alice" }
Backslash escape sequences are mandatory for: double quotes ("), backslashes (\), newlines, carriage returns, tabs, and Unicode characters. An unescaped newline inside a string is a syntax error.
Numbers
JSON numbers cannot have leading zeros (except for 0 itself), cannot be Infinity, cannot be NaN, and cannot have a trailing decimal point. 1. is invalid; 1.0 is valid. Hexadecimal notation (0xFF) is also invalid — JSON numbers are always decimal.
Objects and Arrays
The most common JSON error is the trailing comma:
// INVALID — trailing comma after last property
{
"name": "Alice",
"age": 30,
}
// VALID
{
"name": "Alice",
"age": 30
}
JavaScript (and many modern JSON parsers in lenient mode) silently ignore trailing commas. The JSON spec does not. If your payload is destined for a strict parser — a Go server, a Java API, a strict browser JSON.parse() — a trailing comma will throw a parse error.
Comments Are Forbidden
JSON does not support comments. Not // line comments, not /* block comments */. If you need commented configuration files, use YAML or TOML instead. In JSON, any // or /* is a syntax error.
Common JSON Errors and How to Fix Them
Unexpected Token Error
This is the most frequent parse error. It usually means a trailing comma, an unquoted key, or a single-quoted string. Paste the payload into the JSON validator and it will point you to the exact line and character position of the error.
Unterminated String
Occurs when a string contains an unescaped double quote or a literal newline. For example:
// INVALID — unescaped quote inside string
{ "message": "She said "hello" to me" }
// VALID — escaped quotes
{ "message": "She said "hello" to me" }
Invalid Escape Sequence
Only a specific set of escape sequences are valid in JSON: double quotes, backslashes, forward slashes, backspace, form feed, newline, carriage return, tab, and Unicode hex sequences. Any other backslash sequence is a syntax error in strict JSON, even though JavaScript regex patterns use them.
Number Precision Issues
JSON does not define a maximum number size, but JavaScript's JSON.parse() uses IEEE 754 double-precision floating point, which cannot accurately represent integers above 253 (9,007,199,254,740,992). Database primary keys and Snowflake IDs often exceed this limit. The standard solution is to serialize large integers as strings in JSON, or use a BigInt-aware parser.
Comments · 0
No comments yet. Be the first to share your thoughts.