What makes JSON valid?
JSON is defined by RFC 8259, and its rules are stricter than JavaScript's. A document is valid JSON when:
- Strings and property names use double quotes.
'single'quotes are not allowed. - There are no trailing commas after the last item of an object or array.
- There are no comments. JSON has no
//or/* */syntax. true,falseandnullare lowercase.True,None,undefinedandNaNare not JSON.- Numbers are written in decimal, without leading zeros, a leading
+, or hexadecimal like0x1F. - Special characters inside strings are escaped: a line break is
\n, a tab is\t, a backslash is\\. - The text holds exactly one value. It can be an object, an array or a single scalar such as
42.
How to validate JSON
- Paste your JSON into the editor, select Open file, or drop a file onto it.
- The result appears as you type. Valid JSON shows a summary of its structure.
- If there is an error, it is underlined in the editor. The message shows its line and column, with a suggested fix. Show in input moves your cursor to it.
- Fix the error and the result updates. Only the first error is reported, because one mistake, such as a missing quote, can make everything after it unreadable.
What the validator reports
Syntax errors stop parsing: the validator reports the first one with its exact position, a plain-language message such as "Trailing comma before ]", and how to fix it.
Warnings are valid JSON that is likely to cause problems elsewhere:
- Duplicate keys. The standard says keys should be unique, and parsers disagree about which value to keep.
- Large integers. Numbers above 9,007,199,254,740,991 lose precision when read by JavaScript.
- A byte-order mark. An invisible character at the start of the file that some parsers reject.
A structure summary for valid JSON: the type of the top-level value, how deeply it is nested, and how many objects, arrays, keys, strings, numbers, booleans and nulls it contains. It is a quick way to sanity-check an API response or a data export.
Syntax validation and JSON Schema
This validator answers one question: is this text valid JSON? It does not check whether the data has the shape your application expects, for example that email is present and is a string. That is the job of JSON Schema, which compares a document against a schema you write.
Validating JSON in code and on the command line
When you need to check JSON in a script or CI pipeline:
# jq: prints nothing and exits 0 when valid
jq empty data.json
# Python standard library
python3 -m json.tool data.json > /dev/null
In JavaScript, JSON.parse throws a SyntaxError for invalid input:
function isValidJson(text) {
try {
JSON.parse(text);
return true;
} catch {
return false;
}
}
Be aware that JSON.parse accepts duplicate keys and rounds large integers without warning. This page reports both.