Syntax and types
The complete JSON grammar, the values that look valid but are not, and how JSON compares to a JavaScript object literal.
The whole grammar
{
"id": 42,
"name": "Ada",
"active": true,
"score": 9.5,
"tags": ["math", "code"],
"address": { "city": "London", "postcode": "N1 9GU" },
"manager": null
}| Value | Legal in JSON? | Notes |
|---|---|---|
| string | Yes | double quotes only |
| number | Yes | no NaN, Infinity, hex, leading + or bare .5 |
| object | Yes | keys must be double-quoted strings |
| array | Yes | no trailing comma |
true / false | Yes | lowercase only |
null | Yes | the only null-like value |
undefined | No | omit the key instead |
Date, Map, Set | No | send an ISO 8601 string |
| function, comment | No | not data |
💡
JSON has no comments and no trailing commas on purpose: it is a data interchange grammar rather than a configuration language. When you need comments in a config file, use a JSONC or JSON5 parser and keep plain JSON for what travels over the wire.
Rules that trip people up
{
"line": "first\nsecond",
"path": "C:\\Users\\ada",
"quote": "she said \"hello\"",
"char": "\u00e9"
}- Strings are always double quoted; single quotes are a syntax error, not a style choice.
- Object keys must be quoted:
{id: 1}is not JSON. - Numbers cannot start with
+or a decimal point, and01is invalid while0.1is fine. - The only escapes are
\",\\,\/,\b,\f,\n,\r,\tand\uXXXX; anything else is invalid. - A backslash in a Windows path or in a regular expression must itself be escaped, which is why JSON escaping doubles up.
JSON versus a JavaScript object literal
| Feature | JSON | JS object literal |
|---|---|---|
| Key quotes | required | optional |
| Single quotes | invalid | allowed |
| Comments | invalid | allowed |
undefined values | invalid | allowed |
| Trailing comma | invalid | allowed |
Date, Map, Set | not representable | native |
| Evaluation | inert data | runs as an expression |
// the same data written as a JavaScript object literal
const cfg = {
name: 'app', // comments and single quotes are fine here
retries: undefined, // valid JavaScript, invalid JSON
tags: ['a', 'b',], // trailing comma allowed
};
// converting between the two representations
const text = JSON.stringify(cfg); // {"name":"app","tags":["a","b"]}
const back = JSON.parse(text); // plain data, no functions, no undefinedFAQ
Which MIME type should JSON be served with?
application/json. Serving JSON as text/html is a common way to create an injection hole, because a browser may then render the payload as markup.Can JSON contain Unicode text directly?
Yes. JSON strings are Unicode and UTF-8 is the standard encoding for interchange, so characters can appear literally or as
\uXXXX escapes.Related
CSV vs JSON parse, stringify, revivers and replacers
Last refreshed 2026-09-18.