What counts as valid JSON
JSON is defined by RFC 8259 and ECMA-404. A valid document is a single value: an object, an array, a string, a number, or one of the literals true, false and null. Objects hold zero or more "name": value pairs separated by commas; arrays hold values separated by commas. Strings use double quotes. Whitespace between tokens is ignored.
That is the whole grammar, which is why most invalid JSON comes from writing JavaScript, Python or YAML habits into a JSON file: trailing commas, single quotes, comments, unquoted keys, True instead of true.
How this validator reports problems
The parser stops at the first character it cannot accept and reports three things: the position (line and column), the message (what was found and what was expected), and a hint describing the most likely cause. The right pane shows your document with the failing line highlighted and the exact character underlined, so you do not have to count columns.
Only the first syntax error is reported. JSON has no error recovery; after the first fault the rest of the document is ambiguous. Fix it, and the validator re-runs as you type.
When the document is valid, the validator still checks for duplicate keys. RFC 8259 says names within an object should be unique; when they are not, most parsers keep the last value and drop the earlier one without telling you. Duplicates are reported as warnings with their position.
Messages you may see
| Message | Meaning |
|---|---|
Trailing comma before } / ] | A comma follows the last item. Delete it. |
Missing , before property | Two properties or values are adjacent. Add a comma after the earlier one. |
| Property name must be quoted | A key is written without double quotes. |
| Strings must use double quotes | A string or key uses single quotes. |
| Comments are not allowed | The document contains // or /* */. Config formats such as JSONC and JSON5 allow comments; JSON does not. |
| Unexpected end of input | A bracket or brace is never closed, or the document was truncated. |
| Line break inside a string | A string spans two lines. Usually a missing closing quote. |
Unexpected , after the top-level value | Several top-level values. Wrap them in an array, or you may have newline-delimited JSON. |
NaN, Infinity, undefined is not valid JSON | JavaScript values with no JSON representation. Use null or a string. |
| Unexpected byte order mark | The file starts with U+FEFF. Save it as UTF-8 without BOM. |
Validating JSON in code
JavaScript
try {
JSON.parse(text);
} catch (err) {
// V8: "Unexpected token } in JSON at position 27"
// Firefox: "JSON.parse: unexpected character at line 3 column 1 of the JSON data"
console.error(err.message);
}
Python
import json
try:
json.loads(text)
except json.JSONDecodeError as e:
print(e.msg, "at line", e.lineno, "column", e.colno)
Command line
jq empty data.json # prints nothing on success, an error with line number otherwise
python -m json.tool data.json > /dev/null
Syntax validation versus schema validation
This tool checks syntax: whether the text is well-formed JSON. It does not check structure: whether "age" is present, is a number and is positive. That is the job of JSON Schema, which needs a schema document to validate against. Syntax validation is a prerequisite; a document that fails here will fail every schema too.
Related tools
To fix indentation or minify after validating, use the JSON Formatter. To explore a large valid document, use the JSON Viewer. If the input is actually YAML, the JSON ↔ YAML converter reads it directly.