JSON Validator
Paste your JSON and instantly see whether it's valid. Errors include line numbers when possible.
What validation checks
A JSON validator confirms that a document conforms to the JSON grammar. It checks syntax only - that brackets balance, strings are properly quoted, and values are of legal types. It cannot tell you whether the data is correct, complete or sensible.
That distinction matters. {"age": "forty"} is perfectly valid JSON, and also probably a bug. Validating structure is the job of JSON Schema, which is a separate layer.
Key takeaways
- Validation checks grammar, not meaning.
- The reported error position is where parsing failed, not always where the mistake is.
- Unbalanced brackets are typically reported far from the actual problem.
- JSON Schema validates structure and types; syntax validation does not.
- A byte order mark at the start of a file is a classic invisible cause of failure.
Error messages and what they mean
| Error | Usual cause |
|---|---|
| Unexpected token } in JSON | A trailing comma before the closing brace |
| Unexpected end of JSON input | A bracket or brace was never closed |
| Unexpected token ' in JSON | Single quotes used instead of double |
| Expected property name or } | An unquoted key, or a stray comma |
| Unexpected non-whitespace character after JSON | Two JSON documents concatenated, or trailing content |
| Unexpected token < in JSON | The response was HTML - often an error page, not JSON |
| Bad control character in string literal | A literal newline or tab inside a string |
Why the error position can mislead
A parser reports where it could no longer continue, which is not necessarily where the mistake is. If you forget a closing brace on line 5, the parser happily reads on and only fails at the end of the file - reporting line 500 for a problem on line 5.
- For "unexpected end of input", look for an unclosed bracket, brace or quote somewhere before the reported point.
- For a reported line that looks fine, check the lines immediately above it.
- Use a formatter - pretty-printing makes unbalanced structure visually obvious.
- Bisect large documents. Cut the file in half and validate each part to narrow the search.
Invisible causes of failure
| Problem | Symptom | Fix |
|---|---|---|
| Byte order mark (U+FEFF) | Fails at position 0 despite looking valid | Save the file as UTF-8 without BOM |
| Smart quotes from a word processor | Unexpected token error | Replace with straight double quotes |
| Non-breaking space | Unexpected token error | Replace with a normal space |
| Literal tab inside a string | Bad control character | Escape it as \t |
| Windows line endings inside strings | Bad control character | Escape as \r\n |
| Truncated response | Unexpected end of input | Check for a size or timeout limit upstream |
Syntax validation versus schema validation
| Syntax validation | JSON Schema validation | |
|---|---|---|
| Checks | Grammar and structure | Types, required fields, formats, ranges |
| Catches a missing bracket | Yes | Yes, indirectly |
| Catches a missing required field | No | Yes |
| Catches a string where a number belongs | No | Yes |
| Catches an invalid email format | No | Yes |
| Needs a schema definition | No | Yes |
This tool does syntax validation. If you need to guarantee that an API payload has the right shape, JSON Schema is the appropriate tool and is supported by libraries in every major language.
Avoiding invalid JSON in the first place
- Never build JSON by string concatenation. Use your language's serializer, which escapes correctly every time.
- Validate at API boundaries, not deep inside business logic where the error context is lost.
- Wrap parsing in error handling and log the raw response when it fails - that is how you discover you were sent HTML.
- Check the content type and status code before parsing.
- Add a linter to CI for JSON files kept in version control.
- Use an editor with JSON syntax highlighting, which catches most mistakes as you type.
Frequently Asked Questions
What does a JSON validator check?
It checks that the document follows the JSON grammar - balanced brackets, properly quoted strings, legal value types and correct comma placement. It validates syntax only, not whether the data itself makes sense.
What does "Unexpected token < in JSON at position 0" mean?
That your code tried to parse HTML as JSON. The response was almost certainly a 404 page, a login redirect or a server error page returned where an API response was expected. Check the HTTP status and the raw response body rather than your parsing code.
Why does the error point to a line that looks fine?
Because a parser reports where it could no longer continue, not where the mistake was made. A brace left unclosed on line 5 is only detected at the end of the file. Look above the reported position for unbalanced brackets or quotes.
My JSON looks perfect but still fails at position 0. Why?
Almost certainly a byte order mark - an invisible three-byte prefix some Windows editors add when saving UTF-8. The file looks identical everywhere but the parser sees an unexpected character. Re-save as UTF-8 without BOM.
What is the difference between JSON validation and JSON Schema?
Syntax validation checks that the document parses. JSON Schema checks that it has the right shape - required fields present, values of the correct type, strings matching expected formats. A document can be perfectly valid JSON and still be completely wrong for your application.
Why does my JSON fail with "bad control character"?
Because a literal newline, tab or carriage return appears inside a string. Control characters below U+0020 must be escaped - use \n for a newline and \t for a tab rather than the raw character.
Can I validate very large JSON files here?
Yes, subject to your device's memory. Validation runs in your browser, so very large files of many megabytes may be slow but will generally work. For files that large, a command-line tool is usually more comfortable.
Is my JSON uploaded anywhere?
No. Validation runs entirely in your browser and nothing is transmitted or stored, which matters when the payload contains real customer or production data.