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
}
ValueLegal in JSON?Notes
stringYesdouble quotes only
numberYesno NaN, Infinity, hex, leading + or bare .5
objectYeskeys must be double-quoted strings
arrayYesno trailing comma
true / falseYeslowercase only
nullYesthe only null-like value
undefinedNoomit the key instead
Date, Map, SetNosend an ISO 8601 string
function, commentNonot 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, and 01 is invalid while 0.1 is fine.
  • The only escapes are \", \\, \/, \b, \f, \n, \r, \t and \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

FeatureJSONJS object literal
Key quotesrequiredoptional
Single quotesinvalidallowed
Commentsinvalidallowed
undefined valuesinvalidallowed
Trailing commainvalidallowed
Date, Map, Setnot representablenative
Evaluationinert dataruns 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 undefined

FAQ

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.

CSV vs JSON parse, stringify, revivers and replacers

Last refreshed 2026-09-18.