JSONC / JSON5 Syntax Reference

JSON with Comments and JSON5 extensions compared against standard JSON.

Reference comparing JSONC and JSON5 syntax extensions against strict JSON, including comments, trailing commas, unquoted keys, single quotes, hex numbers and special float values.

What is the difference between JSONC and JSON5?

JSONC (JSON with Comments) is a small superset that adds only line and block comments plus trailing commas; it is what VS Code uses for tsconfig.json and settings. JSON5 is a much broader superset that also allows unquoted keys, single-quoted strings, hexadecimal numbers, leading or trailing decimal points, and special values like Infinity and NaN.

JSONC and JSON5 versus strict JSON

Plain JSON is deliberately minimal: no comments, no trailing commas, double quotes only. Two supersets relax those rules for human-edited config files. JSONC adds just comments and trailing commas. JSON5 goes much further, borrowing many JavaScript object-literal conveniences. This reference compares each feature across all three.

How it works

Both supersets are parsed by dedicated tools, never by JSON.parse. JSONC tolerates comments and trailing commas; JSON5 additionally accepts unquoted keys, single quotes and more:

{
  // JSONC and JSON5: a comment
  key: 'value',        // JSON5 only: unquoted key + single quotes
  hex: 0xFF,           // JSON5 only: hexadecimal
  list: [1, 2, 3,],    // trailing comma in both supersets
}

To consume these formats in a strict-JSON pipeline you either run them through a JSON5/JSONC parser or pre-strip the extensions back to canonical JSON.

Tips and notes

  • VS Code config files (tsconfig.json, settings.json) are JSONC, not JSON.
  • A trailing comma is the single most common reason JSON.parse rejects a config file.
  • Reach for JSON5 when humans edit the file often; keep machine-to-machine APIs on strict JSON.
  • After editing, validate with the right parser so an unquoted key or stray comment is caught early.