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.
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 is the spec.
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. 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.
JSON vs JSON5 vs 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.
Is my JSON uploaded?
No. Parsing and validation run locally in your browser. Nothing leaves the page.