JSON Validator
Validates a JSON string against RFC 8259 and the JavaScript language specification. Configure the validator to be strict or lenient (single quotes, unquoted names, NaN, leading zeroes).
Result
JSON Explained
What does this validator check?
The validator parses your text with a strict parser that implements RFC 8259 (the JSON standard, formerly RFC 4627) and ECMA-404. Every character is examined: when the document is not valid the exact line and column of the first problem is reported together with an excerpt of the source, so you can fix it immediately. While you type, a live badge next to the input tells you whether the document is currently valid.
Because many real-world producers emit JavaScript-flavoured "JSON", the validator can optionally be made lenient. Each option enables one relaxation; everything else is still checked strictly.
The JSON rules
- A document contains exactly one value: an object, an array, a string, a number,
true,falseornull. Nothing may follow it (except whitespace). - Objects are written
{ "name": value, … }. Names must be strings in double quotes. Names should be unique. - Arrays are written
[ value, value, … ]. Elements may be of different types. - Values are separated by commas. A comma after the last element (trailing comma) is not allowed.
- Strings use double quotes only. The characters
"and\and all control characters (U+0000–U+001F, including tabs and line breaks) must be escaped:\" \\ \/ \b \f \n \r \t \uXXXX. No other escape sequence exists. - Numbers are decimal: an optional minus sign, an integer part without leading zeroes (
0alone is fine), an optional fraction and an optional exponent.+1,.5,1.,0x1F,NaNandInfinityare not numbers. - The literals are lower-case:
true,false,null.True,NULLorundefinedare invalid. - Whitespace (space, tab, CR, LF) is allowed between tokens. Comments are not part of JSON.
Strict versus lenient
By default the validator is strict: it accepts exactly what RFC 8259 accepts, which is what JSON.parse(), Java's Jackson (default configuration), Python's json module and most APIs accept. Tick the options above to accept common extensions:
| Option | Accepts | Example | Used by |
|---|---|---|---|
| Accept non-quoted names | Object member names that are bare identifiers | { name: "value" } | JavaScript object literals, JSON5, Jackson ALLOW_UNQUOTED_FIELD_NAMES |
| Accept single-quotes | Strings and names delimited by ' | { 'name': 'value' } | JavaScript, JSON5, Jackson ALLOW_SINGLE_QUOTES |
| Accept 'NaN' values | The tokens NaN, Infinity and -Infinity as numbers | { "ratio": NaN } | Python json.dumps, Jackson ALLOW_NON_NUMERIC_NUMBERS |
| Accept leading zeroes | Integers padded with zeroes | { "code": 007 } | Jackson ALLOW_NUMERIC_LEADING_ZEROS |
| Accept comments | // line and /* block */ comments | { "a": 1 /* note */ } | JSONC (VS Code settings), JSON5, tsconfig.json |
| Accept trailing commas | A comma before a closing } or ] | [1, 2, 3,] | JSON5, JavaScript, Jackson ALLOW_TRAILING_COMMA |
Common mistakes and how the validator reports them
| Mistake | Invalid | Valid | Typical message |
|---|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} | Unexpected '}', expected a property name (trailing comma?) |
| Single quotes | {'a': 'b'} | {"a": "b"} | Property names must be enclosed in double quotes |
| Unquoted keys | {a: 1} | {"a": 1} | Property name 'a' must be enclosed in double quotes |
| Comments | {"a": 1 // one} | {"a": 1} | Comments are not allowed in JSON |
| NaN / Infinity | {"a": NaN} | {"a": null} | 'NaN' is not a valid JSON value |
| Leading zeroes | {"a": 012} | {"a": 12} or "012" | Numbers cannot have leading zeroes |
| Control characters in strings | "line 1 (raw line break) | "line 1\nline 2" | Unescaped line break in string (use \n) |
| Invalid escape | "C:\Users" | "C:\\Users" | Invalid escape sequence '\U' |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} | Missing ',' between properties |
| Missing colon | {"a" 1} | {"a": 1} | Expected ':' after property name |
| Capitalised literals | {"a": True, "b": NULL} | {"a": true, "b": null} | Unexpected token 'True' |
| Several root values | {"a": 1} {"b": 2} | [{"a": 1}, {"b": 2}] | Unexpected character '{' after the end of the JSON document |
| Unbalanced brackets | {"a": [1, 2} | {"a": [1, 2]} | Unexpected character '}', expected , or ] |
A valid example
{
"id": 1001,
"name": "Ada Lovelace",
"active": true,
"score": 98.6,
"tags": ["math", "engine", "notes"],
"address": { "city": "London", "zip": null },
"note": "Escape \"quotes\" and \\backslashes\\, and use \n for line breaks"
}
The MIME type of JSON is application/json and the usual file extension is .json. Files should be encoded in UTF-8 without a byte-order mark.