What counts as well-formed JSON
JSON is defined by RFC 8259 and ECMA-404. A JSON text is exactly one value: an object, an array, a string, a number, or one of the literals true, false, and null. The rules that trip people up:
- Double quotes only. Strings and object keys must be wrapped in
". Single quotes are a syntax error. - No trailing comma.
[1, 2, 3,]and{"a": 1,}are invalid. The comma is a separator, not a terminator. - No comments. There is no
//or/* */in JSON. - Keys must be quoted strings.
{name: "Alice"}is invalid; it must be{"name": "Alice"}. - Numbers are plain. No leading zeros (
0123), no leading+, no leading or trailing decimal point (.5,5.), no hex. An exponent is fine:6.022e23. - No
NaNorInfinity. They are valid JavaScript numbers but not valid JSON. Usenullor a string. - One top-level value. Two objects back to back, or trailing text after the value, is invalid. Newline-delimited JSON (NDJSON) is a different format.
The six errors that cause almost every failure
| Error | Cause | Fix |
|---|---|---|
| Trailing comma | A comma after the last item: {"a":1,} or [1,2,] | Delete the comma before the closing } or ] |
| Single quotes | Copied from JavaScript or Python: {'a': 'b'} | Replace every ' around strings and keys with " |
| Missing comma | Two items with only whitespace between them: {"a":1 "b":2} | Add a comma between every key/value pair and every array element |
| Unquoted key | JavaScript object literal syntax: {name: "Alice"} | Wrap every key in double quotes: {"name": "Alice"} |
| Unescaped character | A raw newline, tab, or " inside a string | Escape it: \n, \t, \" |
| Wrong value type | A JavaScript expression as a value: "date": new Date(), "x": undefined | Serialize it first — an ISO string, a number, null |
JSON vs JSON5 vs JSONC
| Feature | JSON | JSONC | JSON5 |
|---|---|---|---|
Comments // /* */ | No | Yes | Yes |
| Trailing commas | No | Yes | Yes |
| Single-quoted strings | No | No | Yes |
| Unquoted keys | No | No | Yes |
.5, 5., +1, hex, Infinity, NaN | No | No | Yes |
| Typical use | APIs, config sent over the wire, data files | tsconfig.json, VS Code settings.json | Hand-edited config where ergonomics matter |
JSONC and JSON5 are editor and tooling conveniences. An HTTP API, JSON.parse, and most language standard libraries accept strict JSON only, so anything you send to a service you do not control should validate here with leniency mode off.
How to check if JSON is valid
- Paste or type your JSON into the JSON input pane. With Validate as I type on (the default) the verdict updates on every keystroke; turn it off for very large documents and press Validate or Ctrl/Cmd+Enter instead.
- Read the verdict bar. Valid input shows Valid JSON. plus size, depth and counts of keys, objects, arrays, strings, numbers, booleans and nulls. Invalid input shows the line, column and reason for the first error.
- For an error, the Parsed preview pane shows the failing line, up to two lines before it, and a caret under the exact column. Fix that character and the check runs again.
- Once the input is valid, Pretty-print rewrites it with two-space indentation and Minify puts it on one line.
The sample links under the editor load a valid document and four common mistakes, which is a quick way to see what each error message looks like.
Worked examples
1. Missing comma between properties
{
"name": "Alice"
"age": 30
}
The JSON checker reports the position of the token it did not expect, which is the start of the next key rather than the end of the previous line:
Invalid JSON — line 3, column 3: Expected "," or "}" after the property value
1 | {
2 | "name": "Alice"
3 | "age": 30
| ^
2. Trailing comma in an array
{
"tags": ["a", "b",],
"ok": true
}
Invalid JSON — line 2, column 20: Trailing comma before "]" is not allowed in JSON
1 | {
2 | "tags": ["a", "b",],
| ^
Here the caret points at the comma itself, so you can delete it directly.
3. A JSONC config checked in leniency mode
{
// owner
'name': 'Alice',
retries: 3,
}
With leniency mode on, the document parses and every non-standard construct is listed with its line and column:
Parses in leniency mode — but it is not standard JSON (5 non-standard constructs below).
line 2:3 — Line comment ( // ... ) is not valid in standard JSON
line 3:3 — Single-quoted string; JSON requires double quotes
line 3:11 — Single-quoted string; JSON requires double quotes
line 4:3 — Unquoted key "retries"; JSON keys must be in double quotes
line 4:13 — Trailing comma before "}"
Pressing Pretty-print while leniency mode is on rewrites the input as strict JSON: comments are dropped, quotes become double quotes and keys are quoted. That is a quick way to turn a hand-edited config into something JSON.parse accepts.
Edge cases worth knowing
- Byte order mark. A file saved as "UTF-8 with BOM" starts with an invisible U+FEFF character, which is not JSON whitespace. The validator reports an unexpected token at line 1, column 1; re-save the file as plain UTF-8.
- Raw tabs and newlines in strings. Control characters must be escaped, so a pasted tab gives Unescaped control character (0x9) in string. Replace it with
\t. - Duplicate keys.
{"id": 1, "id": 2}is reported as valid, because the grammar allows it, and the preview keeps the last value. Many parsers behave the same way, so treat duplicates as a bug even though they pass. - Big integers.
12345678901234567890is valid JSON, but the preview shows it rounded because browsers parse numbers as 64-bit floats. See JSON big integer precision. - Several documents in a row. NDJSON log lines fail with Unexpected extra content after the JSON value on line 2. Convert them with JSONL to JSON instead.
- Top-level scalars.
"hello",42andnullon their own are valid JSON texts under RFC 8259, although some older parsers only accept an object or array.
When to use the validator and when to use something else
Use this JSON validator online when you need a yes-or-no answer with the exact position of the problem. Syntax is only the first check, though. Valid JSON can still have the wrong shape, so test structure, required fields and value ranges with the JSON Schema validator. For model output that needs repairing rather than diagnosing, LLM JSON repair fixes truncated and chatty responses. To compare two valid documents, use the JSON diff checker; to browse a large one, open it in the JSON viewer.
Questions
What makes JSON valid?
A single value with double-quoted strings and keys, no trailing commas, no comments, no leading zeros or + on numbers, and no NaN or Infinity. RFC 8259 and ECMA-404 define the format.
Why does my JSON fail when it looks fine?
Usually a trailing comma, single quotes, a missing comma between items, an unquoted key, or a JavaScript expression used as a value. Invisible characters are the other suspect: a byte order mark or a raw tab inside a string. The caret shows which character.
Is JSON with comments valid?
No. Comments make it JSONC. Enable leniency mode to parse it anyway and see each comment located.
What is the difference between JSON, JSON5 and JSONC?
JSON is strict. JSONC adds comments and trailing commas. JSON5 also adds single quotes, unquoted keys, and looser numbers. Only strict JSON is safe for arbitrary APIs.
Does the validator check my data against a schema?
No. It checks syntax only: whether the text is well-formed JSON. To check required fields, types and value ranges, use the JSON Schema validator.
Is my JSON uploaded?
No. Parsing and validation run locally in your browser. Nothing leaves the page.