About the JSON5 Validator
JSON5 is JSON with the parts of JavaScript that make a config file bearable. Keys can be unquoted identifiers, strings can use single quotes, comments in both // and /* */ forms are allowed, a trailing comma is legal after the last member, numbers can be hexadecimal, can start or end with a decimal point, and can be Infinity or NaN with an optional sign. Because a strict JSON parser rejects every one of those, running a JSON5 file through a JSON validator produces a misleading error at the wrong place.
The parser here implements the JSON5 grammar directly. When it stops, it names the line and column and says what it expected, so a missing colon after a key, an unterminated block comment or a stray quote is a one glance fix. The editor puts a marker on that line as well. Escapes are checked as strictly as the specification requires, so \u needs four hex digits and \x needs two, while a backslash before a real newline correctly continues the string.
A valid document produces a report counting objects, arrays, keys, strings, numbers and comments, along with the maximum nesting depth and the top level key names, which is a quick sanity check that the file holds what you think. Switch the Show option to convert the document to strict JSON, where Infinity and NaN are written as strings since JSON has no way to express them. For plain JSON with the same line and column reporting, use the JSON Validator.
How to use
- Paste the JSON5 document, or drop a
.json5file onto the left pane. - Read the report, or follow the line and column in the error message to the problem.
- Switch Show to converted strict JSON when you need a file an ordinary parser will accept.
Common questions
- What does JSON5 allow that JSON does not?
- Comments, unquoted keys, single quoted strings, trailing commas, leading plus signs, hexadecimal numbers, numbers starting or ending with a dot, and the values Infinity and NaN.
- How are Infinity and NaN converted to strict JSON?
- They become the strings "Infinity" and "NaN", because the JSON specification has no numeric literal for either one.
- Can it validate a JSONC file with comments?
- Yes. JSONC is a subset of what JSON5 permits, so a tsconfig or a VS Code settings file validates here without complaint.
- Does validation change the order of my keys?
- The report never rewrites your file. The converted JSON view keeps keys in the order they appeared.