JSON & Data
How to Validate JSON and Pinpoint the Exact Syntax Error
Validate JSON syntax and jump to the exact line and column of any error. Learn the rules, the most common mistakes, and how to debug malformed JSON fast.
Try the toolJSON Validator →Few error messages are as unhelpful as Unexpected token } in JSON at position 247. You know something is wrong, but not what, and counting to character 247 by hand is nobody's idea of a good afternoon. Validating JSON tells you precisely whether a document conforms to the spec and, when it doesn't, exactly where it breaks — usually down to the line and column.
What makes JSON valid
JSON's grammar is deliberately tiny. A valid document is a single value: an object, array, string, number, boolean, or null. The rules that trip people up most:
- Keys and string values must use double quotes — never single quotes.
- No trailing commas after the last element of an object or array.
- No comments — JSON has no
//or/* */syntax. - Every
{,[, and"must be balanced and closed. - Numbers can't have leading zeros (
007) or a trailing decimal point (5.).
How validation works
A validator attempts to parse the text against that grammar. If parsing completes, the document is valid; if it fails, the parser reports the offending position. You can reproduce the core of this yourself:
function validateJson(text) {
try {
JSON.parse(text);
return { valid: true };
} catch (err) {
// err.message often includes a line/column or position
return { valid: false, error: err.message };
}
}
validateJson('{"name": "Ada", "active": true,}');
// { valid: false, error: "Unexpected token } ... " } <-- trailing comma
validateJson('{"name": "Ada", "active": true}');
// { valid: true }
The weakness of the raw JSON.parse approach is the error message: browsers report position offsets, not always a friendly line and column. A dedicated validator translates that offset into a line/column and highlights it for you.
A practical walkthrough
Paste your suspect JSON into the JSON Validator. It checks the syntax locally in your browser and, if there's a problem, points you straight to the line and column so you can fix it without hunting.
- Paste the JSON you received or generated.
- Read the pass/fail result.
- On failure, jump to the reported line and column.
- Fix the issue — usually a stray comma, missing quote, or unclosed bracket — and re-validate.
Reading a real error
Say you get an error at line 4, column 3. Look at the end of the line above it too — a missing comma or an unclosed string on line 3 frequently surfaces as an error on line 4, because the parser only realizes something's wrong once it hits the next token.
Common pitfalls
- Copy-paste from JavaScript. Object literals allow unquoted keys and trailing commas; JSON does not. Pasting JS straight in is a top cause of failures.
- Smart quotes. Copying from a word processor or chat can replace
"with curly “ ” characters that look identical but break parsing. - Hidden characters. A stray BOM or non-breaking space at the start of the file can fail validation invisibly.
- Concatenated objects.
{...}{...}is two values, not one document — valid JSON has a single root.
Validation confirms syntax, not shape. Valid JSON can still be missing the fields your app expects — that's schema validation, a separate step.
Where to go next
Once your JSON validates, you'll often want to make it readable with the JSON Formatter, or compare two versions to see what changed using the JSON Diff. All of these run in your browser with no uploads.
Conclusion
Validating JSON turns a cryptic parser complaint into an actionable location. Learn the handful of rules — double quotes, no trailing commas, no comments, balanced brackets — and let a validator do the position-finding. The next time you hit “unexpected token,” you'll be at the fix in seconds instead of scanning character by character.