JSON validator online: what it checks and how to read the errors
What a JSON validator actually checks, the six mistakes behind most parse errors, and why syntactically valid JSON can still be wrong for your application.
A single missing quote can make a 2 MB payload unreadable. The frustrating part is that the error message is often terse, something like "Unexpected token } at position 1843", and it points near the mistake rather than at it. Understanding what a JSON validator actually checks makes those messages much easier to act on. This post covers the rules from RFC 8259, the half dozen mistakes that cause most failures, how to find the real cause when the reported position is misleading, and the difference between valid JSON and JSON that is correct for your application.
What validation means here
When someone says "validate this JSON" they usually mean "check that this parses". The validator runs the text through the grammar defined in RFC 8259 and tells you whether it conforms. The grammar is small. A value is an object, array, string, number, or one of three literals: true, false and null. Objects are braces around comma-separated "key": value pairs, arrays are brackets around comma-separated values, and strings are double-quoted.
That is the whole language. Because it is so small, almost every error comes down to somebody writing something that looks like JSON but borrows from JavaScript, YAML or Python. The rest of this post is basically a tour of those borrowings.
The mistakes behind most failures
Trailing commas lead the list. A comma after the last element, as in [1, 2, 3,], is legal in JavaScript but not in JSON. Single quotes come next: 'name' is not a JSON string, only "name" is. Unquoted keys are the third, common when someone copies an object literal out of source code.
Comments are the fourth. JSON has no comment syntax, so // note and /* note */ both fail. Config formats such as JSONC and JSON5 allow them, which is why a file with comments can work in one tool and fail in another. Fifth, Python and JavaScript values: None, True, undefined and NaN are all invalid, since only lowercase true, false and null exist. Sixth, numbers: no leading zeros, no trailing decimal point, no hex, and no Infinity.
// Invalid: five separate problems
{
name: 'Ada', // unquoted key, single-quoted string
"age": 036, // leading zero
"admin": True, // wrong literal
"scores": [1, 2, 3,], // trailing comma
}
// Valid
{
"name": "Ada",
"age": 36,
"admin": true,
"scores": [1, 2, 3]
}Why the error position is often off
A parser reports where it noticed it was lost, not where you went wrong. Take an unclosed string. If you forget the closing quote on a value, the parser keeps consuming characters as string content until it finds another quote. That next quote is probably the opening quote of the following key, so the parser then sees the key's text as bare characters and fails there. The reported position is one line below the real mistake.
Missing commas behave similarly. If two members run together as "a": 1 "b": 2, the error lands at the second key, which is correct, but people often look at the line above for a stray comma instead of noticing a missing one. When in doubt, read the lines around the position, then work backward by one token. Closing brackets are the other classic: an array closed with a brace, or the reverse, trips the parser at the closing character, but the mismatch began at the opener.
Special characters and escapes
Strings have their own rules. Inside a double-quoted string, a literal double quote must be escaped as backslash-quote, and so must a backslash. Control characters, meaning anything below U+0020 such as a raw newline or tab, must be escaped too. A multi-line value pasted into a string field without turning the newlines into the two characters backslash and n is a very common cause of a parse failure.
Allowed escapes are the quote, backslash, slash, b, f, n, r, t, and a four-hex-digit unicode escape like backslash u 00e9. Anything else after a backslash is invalid, for example backslash followed by a space or by a letter like d. Windows paths are the usual victim. A path typed as C:\temp\new inside a JSON string reads as a tab character followed by "emp", then a newline followed by "ew", which is a nastier bug than an outright error because nothing fails. Write each backslash twice, or use forward slashes.
{
"path": "C:\\temp\\new",
"message": "She said \"done\"",
"multiline": "line one\nline two"
}Valid is not the same as correct
A document can pass every syntax check and still be wrong for your application. {"age": "thirty"} is valid JSON, but not if your code expects a number. A required field might be missing, a date could be in the wrong format, or an array might be empty where one item is required. A syntax validator cannot catch those, because it does not know what you intended.
For structure and types, the standard approach is JSON Schema, which lets you describe required properties, types and constraints, then check documents against that description. Your application code or a library does that job. Treat syntax validation as the first gate, the one that confirms there is a document to examine, and then check meaning separately.
Validate, then look at the data
Once the text is valid, the next step is usually to see it. In View My JSON, Validate and Format are free, as are the Cards, Table and Tree views, so you can confirm the syntax and then inspect the structure without leaving the page. Because the core tools parse in your browser, you can check a payload without sending it to a server and without signing up.
Two related things to keep in mind. First, a file with one JSON object per line, often called NDJSON or JSON Lines, is not a single valid JSON document, so a validator will reject the file as a whole even though every line is fine. Validate it line by line, or wrap the lines in an array. Second, if a file has a BOM at the start, or you pasted it with invisible characters from a document editor, the first character can be the cause of an error that seems to make no sense.