Back to blog
Data Formats7 min read

JSON5 vs JSONC vs JSON: Comments and Trailing Commas

Understand the JSON supersets: what JSONC and JSON5 add over standard JSON, when to use each, the tooling that supports them, and how to convert them back to strict JSON.

By Saifur Rahman Shochib

Standard JSON is deliberately minimal — no comments, no trailing commas, double quotes only. That strictness is perfect for data interchange and miserable for hand-written config. Two supersets fix this: JSONC adds the essentials, and JSON5 goes further toward a relaxed, human-friendly syntax. This guide explains exactly what each adds, when to reach for them, and how to convert back to strict JSON when a parser demands it.

Why JSON is so strict

JSON (RFC 8259) was designed as a data interchange format, where predictability beats convenience. No comments means no place for a parser to disagree; no trailing commas means no ambiguity; double quotes everywhere means one rule. That strictness is exactly why JSON is universally parseable — but it also makes hand-edited config files fragile, since one stray comma breaks the whole file and you cannot leave a note explaining a setting.

What JSONC adds

JSONC means JSON with Comments. Popularized by Visual Studio Code (its settings and tsconfig files are JSONC), it adds two things to standard JSON: single-line and block comments, and trailing commas. That is the whole feature set — it stays very close to JSON, which makes it easy to support and easy to strip back to strict JSON. JSONC is the pragmatic choice when all you really want is to annotate your config and stop fighting commas.

JSONC adds comments and trailing commasjsonc
{
  // the port the server listens on
  "port": 8080,
  "hosts": ["a", "b",]  // trailing comma is allowed
}

What JSON5 adds

JSON5 also allows unquoted keys and single quotesjson5
{
  name: 'Ada',   // unquoted key, single-quoted string
  hex: 0xFF,      // hexadecimal number
  list: [1, 2,],  // trailing comma
}
  • Comments — both single-line and block, like JSONC
  • Trailing commas in objects and arrays
  • Unquoted object keys that are valid identifiers
  • Single-quoted strings and multi-line strings
  • Extra number formats: hexadecimal, leading or trailing decimal points, and positive/negative Infinity and NaN

JSON5 versus JSONC: which to use

Think of it as a spectrum of looseness. JSONC is a minimal, conservative extension — comments and trailing commas, nothing else — and is the right pick when you want JSON that is barely relaxed and widely understood by editor tooling. JSON5 is a fuller human-friendly dialect with unquoted keys and single quotes, better when you are authoring config by hand and want it to feel like writing a JavaScript object.

If a tool you use already speaks one of them (VS Code uses JSONC), follow that convention. For your own files, choose JSONC for maximum compatibility or JSON5 for maximum ergonomics.

They are for authoring, not interchange

Both JSONC and JSON5 are meant for files humans write, not for data sent between systems. Most runtimes, APIs, and data stores accept only strict JSON, so a JSON5 or JSONC file usually needs to be converted before it travels. Keep the relaxed file as your editable source of truth and produce strict JSON as the output.

Converting back to strict JSON

Converting strips comments, removes trailing commas, quotes keys, and normalizes single quotes to double quotes, producing output that passes a standard parser. Note that comments are lost in the process — they are not representable in strict JSON — so keep the original if you need them. The JSON5 Validator checks JSON5 syntax and converts it to clean JSON, and a standard JSON Validator is the right tool when a file must be strict JSON with no authoring conveniences allowed.

Frequently asked questions

What is the difference between JSON5 and JSONC?

JSONC adds only comments and trailing commas to standard JSON. JSON5 adds those plus unquoted keys, single-quoted and multi-line strings, and extra number formats. JSONC is a minimal extension; JSON5 is a fuller human-friendly dialect.

Can standard JSON have comments?

No. Standard JSON (RFC 8259) does not allow comments. To annotate a JSON-like file, use JSONC or JSON5, then convert to strict JSON if a parser requires it — which removes the comments.

What format does VS Code use for settings?

VS Code uses JSONC — JSON with Comments — for its settings.json and for tsconfig.json, allowing comments and trailing commas while staying close to standard JSON.

Will converting JSON5 to JSON keep my comments?

No. Comments are not valid in standard JSON, so they are removed during conversion. Keep your original JSON5 or JSONC file if you want to preserve the comments for future editing.

Should I use JSON5 for an API?

No. APIs and data interchange should use strict JSON for universal compatibility. Reserve JSON5 and JSONC for human-edited configuration files, and convert to strict JSON for anything sent between systems.

Related tools

Try these tools

Keep reading

Related guides