Few things stall a developer faster than a JSON payload that refuses to parse, returning a cryptic error with a character position but little explanation. Because JSON is strict, tiny mistakes cause total failures. The good news: nearly all JSON errors come from a short list of causes, and once you know them, validation and debugging become quick. This guide focuses specifically on validating JSON and fixing what breaks it.
What Validation Actually Checks
Validating JSON means confirming it obeys the JSON specification exactly. A validator checks that:
- Every key and string uses double quotes.
- There are no trailing commas after the last element.
- Braces
{}and brackets[]are correctly matched and nested. - Values are only the allowed types: string, number, boolean, null, object, or array.
- There are no comments or stray characters.
If all of that holds, the JSON will parse in any compliant environment. If any rule is broken, validation fails and points you toward the problem.
The Errors That Cause 90% of Failures
In practice, a handful of mistakes account for the overwhelming majority of invalid JSON:
| Error | Example | Fix |
|---|---|---|
| Trailing comma | [1, 2, 3,] |
Remove the last comma |
| Single quotes | {'a': 1} |
Use double quotes: {"a": 1} |
| Unquoted key | {a: 1} |
Quote the key: {"a": 1} |
| Missing bracket | {"a": 1 |
Add the closing } |
| Comment present | {"a": 1 // note} |
Remove the comment |
| Wrong value | {"a": NaN} |
Use null or a valid number |
Learn to scan for these six and most "broken JSON" moments resolve in seconds.
Step-by-Step: Validate and Fix
Use the JSON Validator, which checks your JSON in the browser.
- Paste your JSON. Drop in the payload, config, or response.
- Validate. The tool reports whether it is valid, and if not, describes the error and its location.
- Jump to the problem. Use the reported position to find the offending character.
- Apply the fix from the table above and validate again.
- Format it with the JSON Formatter once valid, so it is readable.
Tip: When you cannot spot the error visually, work from the position the validator reports and check the characters just before it — many errors (like a missing comma) are flagged at the point where parsing fails, which is slightly after the real mistake.
A Systematic Debugging Approach
When validation fails and the cause is not obvious, work methodically:
- Check the ends first. Confirm the document opens and closes with matching braces or brackets.
- Search for trailing commas. Look at the last item in every object and array.
- Scan the quotes. Ensure every key and string is double-quoted and closed.
- Look for pasted contamination. Copied responses sometimes include leading text, HTML wrapping, or a byte-order mark.
- Diff against a known-good version. If it worked before, a diff checker highlights exactly what changed.
Validation in a Real Workflow
Validation is most valuable early. Validate request bodies before sending them so you catch malformed payloads locally instead of chasing a 400 error from a server. Validate configuration files before deploying so a stray comma does not crash a service on startup. And validate third-party responses while debugging so you can tell whether the problem is your parsing or their data.
Common Mistakes to Avoid
- Assuming JavaScript rules apply. JS is lenient; JSON is not. Single quotes, trailing commas, and comments are all invalid JSON.
- Fixing the wrong spot. The error position is where parsing failed, which can be just after the actual mistake.
- Editing minified JSON by hand. Format it first so the structure is visible.
- Pasting sensitive payloads into unknown sites. Use a browser-based validator to keep data private.
Conclusion
Validating JSON is about knowing the rules and the short list of ways they get broken. Double quotes, no trailing commas, matched brackets, allowed values, no comments — check those and almost every payload comes back valid. When it does not, work from the reported position, scan for the usual suspects, and diff against a working version. It turns JSON debugging from guesswork into a quick, repeatable process.
Validate your JSON now with the free JSON Validator — private, instant, and always in your browser.