How to Validate JSON and Fix the Most Common Errors
Updated · 7 min read · MetaSol Technologies
Validating JSON answers one question: will a standard parser accept this text? A good validator also tells you where it failed and why. This guide covers the errors you are most likely to meet and how to fix each one.
Paste your document into the JSON Validator to follow along.
1. Trailing commas
{ "a": 1, "b": 2, }
JavaScript tolerates a comma after the last item, but JSON does not. Fix: delete the final comma. The validator points at the comma itself, not at the closing bracket.
2. Single quotes
{ 'name': 'Ann' }
JSON strings and keys use double quotes only. Fix: replace ' with ". If the text itself contains a double quote, escape it as \".
3. Unquoted keys
{ name: "Ann" }
Fix: { "name": "Ann" }. This often happens when copying a JavaScript object literal.
4. Invalid escape sequences
{ "path": "C:\Users\Ann" }
A backslash starts an escape, and \U is not one of the valid escapes (\" \\ \/ \b \f \n \r \t \uXXXX). Fix: double each backslash: "C:\\Users\\Ann", or use forward slashes.
5. Comments
{
// retry count
"retries": 3
}
JSON has no comments. Fix: remove them, or move the explanation into a field such as "_comment". If your tool officially supports JSONC (for example VS Code settings), the file is not plain JSON and other parsers may reject it.
6. Line breaks inside strings
A string must be on one line. Raw line breaks inside quotes are errors. Fix: use \n. If the error appears on a line that looks fine, check the previous line for a missing closing quote.
7. Special numbers and literals
NaN, Infinity, undefined, True, None and numbers with leading zeros like 007 are not JSON. Fix: use null, lower-case true/false, or a string such as "007" when the leading zeros matter (postal codes, phone numbers).
8. Invisible characters
Text copied from web pages, PDFs or word processors can contain non-breaking spaces or smart quotes (“ ”). They look normal but are not valid JSON syntax. The validator reports them explicitly. Fix: retype the character.
Warnings: duplicate keys
{ "id": 1, "id": 2 }
The standard discourages duplicate keys but does not ban them, so the validator reports a warning, not an error. Treat it as a bug anyway: some parsers keep the first value, most keep the last, and a few reject the document.
Beyond syntax: schema validation
Valid syntax does not mean valid data. {"age": "forty"} is valid JSON, but your application may need a number. To check types, required fields and allowed values, describe your data in a JSON Schema and use the JSON Schema Validator.