JSON5

A proposed extension to the JSON format that allows for comments, trailing commas, and unquoted keys, making it significantly more human-readable.

JSON5 is an unofficial, yet highly popular, extension to the standard JSON format. Its primary goal is to make JSON easier for humans to write and maintain by borrowing features directly from ECMAScript 5 (JavaScript).

While standard JSON is incredibly strict (failing on a single misplaced comma), JSON5 is forgiving. It is specifically designed for configuration files where human readability and developer experience are prioritized over strict machine parsing.

Key Features of JSON5

  • Comments: Supports both single-line (//) and multi-line (/* */) comments.
  • Trailing Commas: Objects and arrays can have a comma after the final element without throwing a syntax error.
  • Unquoted Keys: Object keys do not require double quotes if they are valid identifiers.
  • Single Quotes: Strings can be wrapped in single quotes (') instead of double quotes.
  • Multi-line Strings: Strings can span multiple lines by escaping the newline character.

Example of JSON5

{
  // This is a single-line comment
  unquotedKey: 'Single quoted string',
  
  /* This is a 
   multi-line comment 
  */
  trailingComma: [
    1,
    2,
    3, // Notice the trailing comma here
  ],
  
  multiLineString: "This string spans \
multiple lines.",
  
  numbers: [Infinity, NaN, +10, -10, 0x1A] // Extended number formats allowed
}

When to use JSON5

JSON5 is fantastic for environment variables, build configs, and developer tools (for instance, Apple uses JSON5 heavily in Xcode configuration). However, you should never use JSON5 for standard REST API responses, as standard JSON parsers (likeJSON.parse() in browsers or native server libraries) will immediately throw an error when they encounter comments or unquoted keys.