JSON format guide

JSON5 vs JSON

JSON5 is a superset-like format designed to make hand-written configuration easier. It allows several JavaScript-style conveniences that strict JSON rejects, including comments, trailing commas and some unquoted property names.

Quick answer

Use strict JSON for maximum interoperability. Use JSON5 only when both the producer and consumer explicitly support it and human-edited configuration benefits from the relaxed syntax.

What JSON5 adds

JSON5 permits comments, trailing commas, single-quoted strings, unquoted identifier-style object keys, hexadecimal numbers and several other conveniences. These are intentionally outside strict JSON.

Why strict JSON still matters

APIs, databases, validators and standard JSON.parse implementations expect strict JSON. A .json5 file may look familiar but cannot be assumed to work in a JSON-only parser.

Convert before crossing system boundaries

If configuration is authored in JSON5 but sent to an API, parse the JSON5 with a supporting library and serialize the resulting value as strict JSON. Do not rely on downstream systems accepting relaxed syntax.

JSON5 syntax that strict JSON rejects

{
  // JSON5 comment
  unquotedKey: 'value',
  enabled: true,
}

Related JSON tools and guides

Frequently asked questions

Can JSON.parse read JSON5?

No. Native JSON.parse expects strict JSON syntax.

Is every JSON file valid JSON5?

Standard JSON is generally compatible with JSON5 parsers, but the reverse is not true.

Should APIs return JSON5?

Usually no. Strict JSON has far broader interoperability for APIs and machine-to-machine exchange.