JSON Validator
Paste JSON to check it against the standard, with the exact error message and position when something is wrong.
Validate JSON Online
A single stray comma is enough to make an API reject a request or a configuration file fail to load, and the resulting error is not always helpful. Pasting the document into a validator tells you in a second whether it is valid JSON and, if not, exactly where it breaks.
This page opens the JSON Formatter, which validates with the browser's standards-compliant parser on every change and formats the document when it is valid.
The errors a validator finds most often
| Mistake | Invalid | Valid |
|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} |
| Single quotes | {'a': 'x'} | {"a": "x"} |
| Unquoted key | {a: 1} | {"a": 1} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Comment | {"a": 1 // note} | Remove the comment |
| Unescaped newline in a string | a line break inside "…" | "line 1\nline 2" |
| Special values | NaN, undefined | null or a number |
Reading the error message
Browsers report JSON errors with a position, for example "Expected double-quoted property name in JSON at position 12". Position counts characters from zero, so it points to the character where the parser gave up. The real mistake is usually just before it: the comma before a closing brace, or the quote that should have been a double quote.
Valid is not the same as correct
A validator checks syntax, not meaning. JSON with a misspelled key, a number sent as a string or a missing required field is still valid JSON. To check structure, use a JSON Schema validator in your code or CI. And watch out for duplicate keys: they are technically allowed, but most parsers silently keep only the last one.
Validating in code
- JavaScript:
JSON.parse(text)insidetry/catch - Python:
json.loads(text), orpython -m json.tool file.jsonon the command line - jq:
jq empty file.jsonprints nothing when the file is valid - PHP:
json_validate($text)since PHP 8.3
Once it is valid, JSON Minify strips the whitespace for transport.