8 min read
How to validate JSON and fix common errors
A practical guide to JSON validation, parser messages, and the most common syntax mistakes developers run into.
Table of contents
What validation checks
JSON validation checks syntax. It asks whether the text can be parsed by a JSON parser. If the parser can read the entire document, the JSON is syntactically valid. If the parser stops, the validator reports the error.
Validation does not mean the data is correct for your application. A payload can be valid JSON and still be missing a required field. Use schema or application validation for those rules.
Common syntax errors
The most common errors are trailing commas, single quotes, unquoted keys, comments, undefined values, and unescaped characters inside strings. These often appear when someone copies a JavaScript object and treats it as JSON. JavaScript object literals and JSON look similar, but JSON is stricter.
Another common issue is a partially copied response. If an array or object is missing its closing bracket, the validator will fail near the end of the input. Look for matching braces and brackets before chasing deeper issues.
How to use parser errors
Parser errors usually point to the first place where the parser got confused. That location may not always be the root cause, but it is the best place to start. For example, a missing quote earlier in the document can make a later comma look invalid.
Fix one issue, then validate again. Parsers stop at the first syntax problem, so a document can have several errors that appear one at a time.
A reliable validation workflow
Start by pasting the JSON into a validator. If it passes, format it so the structure is readable. If you plan to compare it to another payload, format both before using a diff tool. If you plan to convert it to CSV or XML, validate first so the converter starts from a known-good input.
When the JSON came from production logs, be careful with secrets. Redact tokens, email addresses, and private data before sharing payloads in tickets or documentation.
Related guides
What is JSON and why developers use it
A practical explanation of JSON, where it appears in development, and why its simple structure made it the common language of APIs.
How to format JSON online
Learn when to format JSON, how online formatters work, and what to check when formatting fails.
JSON vs YAML
JSON and YAML both describe structured data, but they make different tradeoffs around readability, strictness, and tooling.
FAQ
What is JSON validation?
JSON validation checks whether text follows JSON syntax and can be parsed.
Is syntax validation the same as schema validation?
No. Syntax validation checks parseability. Schema validation checks required fields and data shapes.
Why are trailing commas invalid?
The JSON grammar does not allow a comma after the last item in an array or object.
Can comments be used in JSON?
No. Standard JSON does not support comments.