How to Format and Validate JSON
JSON (JavaScript Object Notation) is the standard data interchange format for APIs, configuration files, and web services. It is easy for humans to read and write, and easy for machines to parse. Formatting (pretty-printing) adds indentation and line breaks to make nested JSON readable; minifying removes whitespace to reduce file size. Valid JSON follows strict syntax rules — a single missing comma or unquoted key will break parsing.
Last updated: March 31, 2026
The Formula
JSON Structure Rules:
• Strings must use double quotes (not single quotes)
• Keys must be quoted strings
• Values: string, number, boolean, null, object {}, or array []
• No trailing commas after the last item
• No comments allowed
• Top-level must be an object {} or array []Variable Definitions
| Symbol | Name | Description |
|---|---|---|
| {} | Object | An unordered collection of key-value pairs, e.g. {"name": "Alice", "age": 30} |
| [] | Array | An ordered list of values, e.g. [1, 2, 3] or [{"id": 1}, {"id": 2}] |
| null | Null | Represents an intentionally absent value — written as the literal null (not a string) |
Step-by-Step Example
The following minified JSON has an error. Identify it, fix it, and format it.
Given
Solution
- 1Error 1: keys must be quoted strings:
name → "name", age → "age", active → "active" - 2Error 2: strings must use double quotes:
'Alice' → "Alice" - 3Error 3: trailing comma after last value:
true, → true (remove the comma) - 4Format with indentation:
{ "name": "Alice", "age": 30, "active": true }
Valid formatted JSON: {"name": "Alice", "age": 30, "active": true}
Ready to calculate?
Use the free JSON Formatter — instant results, no sign-up.
Common Mistakes to Avoid
Using single quotes — JSON requires double quotes for all strings and keys.
Trailing commas after the last item — valid in JavaScript but illegal in JSON.
Adding comments — JSON has no comment syntax. Use a separate documentation field or a .jsonc parser for config files.
Using undefined or NaN — these JavaScript values do not exist in JSON. Use null instead.