How to Format, Validate, and Fix JSON Online — Complete Guide 2026
Learn how to format messy JSON, validate syntax, auto-repair common errors, and sort keys using a free browser-based JSON formatter tool. Covers the most common JSON errors and how to fix them.
Need to format or fix JSON right now? Use the free JSON Formatter & Repair Tool — paste JSON, click Format or Fix, get clean valid JSON instantly. Supports sort keys, 2/4/8-space indent, and auto-repair. 100% browser-based.
What Is JSON Formatting?
Raw JSON from APIs often looks like this:
{"name":"Alice","age":30,"address":{"city":"Mumbai","zip":"400001"}}
After formatting (pretty-printing) with 2-space indent:
{
"name": "Alice",
"age": 30,
"address": {
"city": "Mumbai",
"zip": "400001"
}
}
The 5 Most Common JSON Syntax Errors
1. Trailing Comma
// Wrong:
{ "name": "Alice", "age": 30, }
// ^ trailing comma
// Correct:
{ "name": "Alice", "age": 30 }
JavaScript allows trailing commas in objects and arrays, but JSON does not. This is the single most common JSON error when copying JS objects.
2. Single Quotes Instead of Double Quotes
// Wrong:
{ 'name': 'Alice' }
// Correct:
{ "name": "Alice" }
JSON requires double quotes around all keys and string values. Single quotes are only valid in JavaScript, not JSON.
3. Unquoted Keys
// Wrong:
{ name: "Alice" }
// Correct:
{ "name": "Alice" }
In JavaScript you can write object keys without quotes. In JSON, all keys must be double-quoted strings.
4. JavaScript Comments
// Wrong:
{
// user name
"name": "Alice"
}
// Correct: remove all comments
JSON does not support // or /* */ comments. If you need comments in configuration, use JSONC (JSON with comments) format — or switch to YAML which does support comments.
5. undefined, NaN, or Infinity
// Wrong:
{ "value": undefined, "ratio": NaN }
// Correct:
{ "value": null, "ratio": null }
JSON only supports null, not JavaScript's undefined, NaN, or Infinity. Replace them with null or remove the key entirely.
How to Format JSON in 3 Steps
- Open the free JSON Formatter
- Paste your JSON into the input panel
- Click Format — the output is pretty-printed with 2-space indent
How to Auto-Repair Broken JSON
- Paste the broken JSON into the formatter
- Click Fix — the tool automatically repairs trailing commas, single quotes, unquoted keys, comments, and undefined values
- A list of all changes made is shown below the output
- If errors remain after Fix, the Validate tab shows the exact line and character position of any remaining issues
Related Developer Tools
- JSON Minifier — compress JSON by removing all whitespace
- JSON Diff Tool — compare two JSON objects to find changes
- JSON Tree Viewer — explore JSON structure as an interactive tree
- JSON to YAML — convert JSON for Kubernetes and config files
FAQs
How do I format JSON online for free?
Paste your JSON into a free JSON formatter tool, choose your indentation (2 or 4 spaces), and click Format. The tool adds proper line breaks and indentation to make the JSON human-readable. No signup or upload required.
What are the most common JSON syntax errors?
The 5 most common JSON errors are: (1) trailing comma after the last item, (2) single quotes instead of double quotes, (3) unquoted object keys, (4) JavaScript-style comments (// or /* */), and (5) undefined or NaN values. A JSON repair tool can fix all of these automatically.
What is the difference between JSON formatting and validation?
Formatting (beautifying) adds indentation and line breaks to make JSON readable. Validation checks if the JSON is syntactically correct — proper quotes, matching braces, valid values. You must fix validation errors before formatting can work.
How do I fix a JSON SyntaxError?
Common fixes: replace single quotes with double quotes, remove trailing commas, add missing quotes around keys, remove JavaScript comments, replace undefined/NaN with null. Use the Fix mode in a JSON formatter to apply all these repairs automatically.
Sponsored