ToolStackToolStack
Browse Tools →
Home/Blog/JSON Formatting Guide
EngineeringApril 16, 2026 · 7 min read

JSON Formatting Guide for Developers: Syntax, Validation & Common Errors

JP

Justin Pirrie

Founder, ToolStack · April 16, 2026

TL;DR

  • → All JSON keys must be double-quoted strings — single quotes are invalid.
  • → Trailing commas are not allowed and will throw a parse error.
  • → Use the free JSON Formatter to validate and beautify instantly in your browser.
Sponsored

Advertisement Space

JSON (JavaScript Object Notation) is the default language of APIs, configuration files, and data storage across virtually every modern stack. Despite its apparent simplicity, it has strict syntax rules that catch developers out repeatedly — especially the ones that work silently in JavaScript but break immediately in JSON.

The Six JSON Data Types

JSON supports exactly six value types. Understanding them prevents the most common serialisation bugs.

TypeExampleNotes
String"hello"Always double-quoted. Single quotes are invalid.
Number42, 3.14, -7No quotes. NaN and Infinity are not valid JSON numbers.
Booleantrue, falseLowercase only. True or False will parse error.
NullnullLowercase. undefined is not a valid JSON value.
Array[1, "two", true]Ordered list. Can mix types. No trailing comma.
Object{"key": "value"}Keys must be strings. No trailing comma on last pair.

The Most Common JSON Errors

1. Trailing Commas

This is the most frequent JSON error. JavaScript objects and arrays allow trailing commas; JSON does not. The last item in an object or array must have no comma after it.

Invalid — will throw SyntaxError

{
  "name": "Justin",
  "role": "founder",   ← trailing comma
}

Valid

{
  "name": "Justin",
  "role": "founder"
}

2. Single-Quoted Keys or Values

JSON requires double quotes. Single quotes are not valid, even though they work fine in JavaScript object literals. This catches people who copy-paste from JS code into a JSON file.

Invalid

{'name': 'Justin'}

3. Unescaped Special Characters in Strings

If a string contains a double quote, backslash, or control character (like a newline), it must be escaped. A raw newline inside a JSON string is invalid.

Escape sequences

\" → escaped double quote
\\ → escaped backslash
\n → newline
\t → tab

Validate and Format Without Installing Anything

When you're debugging an API response or cleaning up a config file, you don't need a local install or a paid tool. ToolStack's JSON Formatter runs entirely in your browser — paste any JSON, get instant validation with exact error positions, and a clean formatted output you can copy back in one click.

It also handles minification (compress JSON for API payloads) and tree-view navigation for large nested structures — both free, no signup.

Frequently Asked Questions

What is the difference between JSON and JavaScript objects?

JSON is a text format — a string. A JavaScript object is a live data structure in memory. JSON requires all keys to be double-quoted strings, does not allow trailing commas, and cannot contain functions, undefined values, or comments. JavaScript objects are more permissive. JSON.parse() converts a JSON string into a JS object; JSON.stringify() does the reverse.

Why does JSON not allow comments?

JSON was designed by Douglas Crockford as a minimal, machine-readable data interchange format. Comments were intentionally excluded to keep parsing unambiguous and fast. If you need annotated config files, consider JSONC (JSON with Comments, used by VS Code) or YAML instead.

What is the difference between null and undefined in JSON?

JSON supports null as a valid value. It does not support undefined at all — if you try to JSON.stringify() an object with undefined values, those keys are silently dropped from the output. This is a common source of bugs when serialising JavaScript objects.

How do I validate JSON without installing anything?

Use ToolStack's free JSON Formatter — paste your JSON, and it instantly highlights syntax errors with the exact line and character position. No signup, no install, runs entirely in your browser.

Back to Blog