JSON
How to Validate JSON: Find the Exact Line and Column of a Syntax Error
Published 2026-08-15 · 7 min read
TL;DR: Validate JSON by pasting it into the JSON validator, which parses the document and reports the exact line and column of the first syntax error.
The frustrating thing about malformed JSON is that it fails without a hint. A parser says unexpected token and leaves you to guess. The validator removes the guessing: it walks the document token by token and stops at the first violation with a line and column, so a missing comma or an unclosed brace is found in seconds. The grammar a validator applies comes from the JSON specification.
Why does JSON fail to parse?
JSON has a strict grammar, and the grammar is where most of the mistakes live. Trailing commas are the most common offender because JavaScript object literals allow them. Single-quoted strings, unquoted keys and comments are the next tier, because they are legal in JavaScript or JSONC but not in JSON. A validator exists to catch exactly these.
How do you validate JSON in a browser?
Paste the document into the JSON validator. The validator parses the whole document and, on failure, shows the error message, the line and the column. On success it confirms the document is valid.
The validator also catches the case where a document is technically valid JSON but has a trailing comma inside an object or array nested several levels deep. The parser reaches the exact position where the grammar fails, which is the difference between a vague message and a fixable location.
How do you validate JSON in code?
In JavaScript, JSON.parse is the validator. It throws a SyntaxError on invalid input, and the message includes a position index. Wrap it in a try/catch to turn a crash into a readable report:
try {
JSON.parse(text);
console.log('valid JSON');
} catch (err) {
console.error('invalid JSON:', err.message);
}In Python, json.loads plays the same role and reports the line and column in its error:
import json
try:
json.loads(text)
print('valid JSON')
except json.JSONDecodeError as err:
print(err.lineno, err.colno, err.msg)How do you validate JSON in the browser console?
Every browser exposes JSON.parse in the console, which makes it a zero-install validator. Open DevTools, paste the document into a JSON.parse() call and press Enter. A valid document returns the parsed object; an invalid one throws a SyntaxError with a position. It is the same engine the online validator uses, minus the line and column formatting.
JSON.parse('{"a": 1,}');
// SyntaxError: Expected double-quoted property name in JSON
// at position 8 (line 1 column 9)The position in the message is a character offset into the string, so for a long document it is less useful than a line and column. That is the case for using a validator that formats the location, but for a quick check on a small snippet the console is the fastest path.
What are the most common validation errors?
| Error | Cause | Fix |
|---|---|---|
| Unexpected token } | Missing comma or a brace closed too early | Add the missing comma or remove the extra brace |
| Unexpected token , line 1 | Stray comma after the last value | Remove the trailing comma |
| Unexpected token in JSON at position N | A value outside the six types | Check for single quotes, unquoted keys or an unescaped control character |
| Unterminated string | A quote opened and never closed | Close the string or escape the quote inside it |
| Comment not allowed | A `//` or `/* */` in the document | Remove comments or use a JSONC parser |
What does valid JSON actually mean?
Valid JSON means the document parses under the JSON grammar in RFC 8259. It does not mean the document matches the shape your application expects. An object is valid JSON whether it has the key your code reads or not; schema validation is a separate step. If you need both, validate syntax first, then check the required keys with a schema validator in your language.
So a valid document and a correct document are different checks. Syntax validation answers one question: did this parse? Schema validation answers the next: does it have the right keys, the right types and the right ranges? Most teams need both, and running the cheap check first means you are not debugging a schema mismatch on top of a syntax error.
What is JSON Schema and do you need it?
JSON Schema is a separate JSON document that describes constraints on other JSON: required keys, allowed types, minimum and maximum lengths, enums and patterns. It is used by API validation middleware and by code generators. A validator for syntax is not a JSON Schema validator, and the tools are different. Start with syntax, then add a schema library when the same shape is validated more than a couple of times.
How do you validate JSON that contains JSON?
A string value can itself contain a JSON document. A common source of confusion is an API that returns a JSON string rather than a JSON object. Paste the outer document to validate its syntax; if it is valid but contains a string that is supposed to be JSON, paste that string on its own to validate the inner document.
Related Tools
Related Guides
Common JSON Errors: The Five Mistakes That Break Every Parse
The short list of JSON parse failures - trailing commas, unquoted keys, missing commas, comments and unbalanced braces - with symptom, cause and fix.
JSON Syntax Guide: The Six Value Types and the Rules That Catch You
A complete walkthrough of JSON syntax: objects, arrays, strings, numbers, booleans and null, plus the edge cases that break real documents.
How to Format JSON: Readable Output in the Browser, Editor or Terminal
Format minified JSON for readability with an online formatter, an editor shortcut, or a command-line tool like jq or python -m json.tool.
JSON vs YAML: Which Format Should You Use, and How Do You Convert?
JSON for data crossing system boundaries, YAML for configuration humans write. Compare syntax, footguns and how to convert between them losslessly.
Frequently Asked Questions
Is empty input valid JSON?
No. An empty string is not a JSON value. Valid JSON must contain one of the six types: object, array, string, number, boolean or null.
Why does my JSON parse in one tool but not another?
The tool is probably tolerant. Browsers and editors often accept trailing commas, comments and single quotes; strict parsers reject them. Use a strict validator to find the difference.
What is the position number in a JavaScript error?
JSON.parse reports an index into the string. It is less readable than a line and column, which is why the validator converts it into the location you can actually use.
Can JSON contain comments?
No. Comments are not part of the JSON grammar. Some formats such as JSONC and JSON5 add them, but a strict validator rejects the document.
How do I validate a very large JSON file?
Paste the whole document or a section of it. A validator is linear in the size of the input, and the error reports the exact line, so you can also strip the file down to the failing region and validate that.