Mastering JSON: Formatting, Minification, and Common Syntax Errors
JavaScript Object Notation (JSON) is the lingua franca of web services and modern APIs. Yet even senior engineers occasionally stumble over strict syntax requirements defined by RFC 8259.
The 3 Most Common JSON Syntax Mistakes
Browsers and programming languages are strict when parsing JSON. Unlike JavaScript object literals, JSON specifications forbid lenient syntax:
1. Trailing Commas
In standard JavaScript, leaving a trailing comma in an object or array is valid. In JSON, it results in an immediate SyntaxError:
// ❌ Invalid JSON
{
"name": "Toolora",
"active": true,
}
// ✅ Correct JSON
{
"name": "Toolora",
"active": true
}
2. Single Quotes Instead of Double Quotes
All string values and property keys must be wrapped in standard double quotation marks ("..."). Single quotes are not permitted.
3. Unquoted Keys
Keys must always be strings. Writing { status: 200 } will fail; it must be { "status": 200 }.
When to Prettify vs When to Minify
During local debugging and code reviews, formatting JSON with 2-space or 4-space indentation is essential for cognitive clarity. In production, however, every byte counts. Stripping indentation and whitespace can reduce payload sizes by 25% to 40% before network transmission.
Use the Toolora JSON Formatter & Validator to inspect line-accurate syntax errors, sort keys alphabetically, and minify payloads directly in your browser.