How to Format, Validate, and Fix Common JSON Errors — FetchToolKit
Learn how to spot and fix trailing commas, missing quotes, comments, and formatting issues in JSON files quickly.
On this page (3 sections)
Key Takeaways & Benefits
Valid JSON requires double quotes ("...") around every property name and text string—single quotes and unquoted keys will cause errors.
Trailing commas after the last item in an object or list, as well as // or /* */ comments, are not allowed in standard JSON.
Sorting object keys alphabetically makes it easy to compare two JSON files side by side without changing the order of items inside arrays.
Formatting and validating JSON directly in your browser keeps API responses and configuration files private on your device.
1. Essential Rules for Valid JSON
JSON (JavaScript Object Notation) is the most common format for exchanging data between web apps, APIs, and configuration files. Although it looks similar to JavaScript code, JSON has much stricter rules so every programming language can read it reliably.
A valid JSON file can only contain six types of values: objects ({ ... }), arrays ([ ... ]), double-quoted text strings ("..."), numbers, booleans (true or false), and null.
| Mistake | Broken Example | Valid in JSON? | How to Fix It |
|---|---|---|---|
| Trailing Comma | {"name": "Alex",} | Invalid | Remove the comma after the last item: {"name": "Alex"} |
| Comments in File | // note or /* comment */ | Invalid | Remove comments before saving as standard JSON |
| Unquoted Keys | {status: "active"} | Invalid | Wrap property names in double quotes: {"status": "active"} |
| Single Quotes | {'status': 'active'} | Invalid | Use double quotes instead: {"status": "active"} |
| Special Number Words | NaN, Infinity, .5 | Invalid | Use standard numbers (like 0.5) or null |
| Raw Line Break in Text | "line 1 line 2" | Invalid | Use \n inside strings for line breaks |
Tip: You can apply these settings directly in your browser using our free JSON Formatter.
2. Finding Syntax Mistakes and Cleaning Up Comments
When a large JSON file has a single missing comma or extra quote, finding the mistake by scrolling through hundreds of lines can be frustrating. Our JSON Validator points directly to the exact Line and Column number where the issue occurred and shows a visual pointer (^) right under the problem.
Many code editors allow comments (//) and trailing commas in configuration files, which fail when copied into strict JSON tools. Clicking Auto-Fix Comments & Trailing Commas removes comments and extra commas automatically while keeping web links like "https://..." inside your text intact.
// Before (contains a comment and a trailing comma):
{
// Webhook notification address
"webhookUrl": "https://fetchtoolkit.com/hooks/v1",
"retries": [1, 2, 5,],
}
// After clicking Auto-Fix (valid JSON):
{
"webhookUrl": "https://fetchtoolkit.com/hooks/v1",
"retries": [1, 2, 5]
}3. When to Prettify, Sort Keys, or Minify JSON
Use Format / Beautify (with 2 or 4 spaces) when you want to read or edit a compact single-line API response comfortably. If you are comparing two JSON files to see what changed, check Sort Keys (A-Z) so all object properties appear in the exact same alphabetical order.
Once you are done editing, switch to Minify mode to remove extra spaces and line breaks—making the JSON string 15% to 35% smaller for faster network requests or compact storage.
Frequently Asked Questions
Why should I format JSON in my browser instead of an upload-based site?
JSON files often contain API responses, configuration settings, or customer records. Formatting JSON directly in your browser ensures your data never leaves your device.
Does sorting JSON keys change the order of items inside arrays?
No. Enabling Sort Keys (A-Z) only reorders named object properties alphabetically ({ "b": 1, "a": 2 } becomes { "a": 2, "b": 1 }) while keeping the order of items inside lists ([1, 2, 3]) untouched.