JSON versus JSONC

JSON vs JSONC explained: what JSONC adds to JSON, how the two differ on comments, trailing commas and parser support, and how to choose and convert safely.

JSON and JSONC look almost identical. The difference is not cosmetic: it decides which parsers will accept a file, which validators will flag it, and whether the file can be sent to a service that expects standard JSON. This guide explains what JSONC adds, how the two formats compare, and how to tell which one suits a given file.

What JSONC actually changes

JSON is a data format defined by RFC 8259 and ECMA-404. Its grammar has no comment syntax. A JSON document contains only objects, arrays, strings, numbers, true, false and null, separated by the required punctuation and optional whitespace.

JSONC, short for "JSON with Comments," is JSON with comments allowed. It typically accepts two comment forms: line comments that start with two slashes, and block comments wrapped in slash-asterisk and asterisk-slash. Some JSONC parsers also accept trailing commas after the last item in an object or array. Others do not.

Comments do not change the data. A parser that understands JSONC discards them and produces the same values the equivalent JSON would produce. The change is in the file's syntax, so the effect is about which tools accept the file, not about what the data means.

The following matched pair is illustrative and was not produced by a specific tool. Both describe the same settings.

// JSONC
{
  // Port used by the local dev server
  "port": 8080,
  /* Set to false before deploying */
  "debug": true,
}
// JSON (the comment above this line is not part of the file)
{
  "port": 8080,
  "debug": true
}

The JSONC version carries explanations and ends with a trailing comma. The JSON version holds the same two values and is accepted by any standards-compliant JSON parser.

There is no single JSONC rulebook

JSON has a formal standard. JSONC has no single, universally adopted specification of equivalent standing. The name refers to a convention that tools implement individually, so details vary between parsers. The most common differences are:

  • Whether trailing commas are accepted, rejected or reported as warnings.
  • Whether block comments may appear anywhere whitespace is allowed.
  • Whether the parser expects a .jsonc extension or reads JSONC from files named .json.
  • Whether a formatter keeps comments when it reformats the file.

Because of this, the label "JSONC" on a file or tool does not guarantee how that file will be parsed. The documentation of the tool that will read the file is the authority. If it does not say whether comments or trailing commas are allowed, treat the behavior as unconfirmed and test it with a small sample before relying on it.

JSONC is also distinct from JSON5. JSON5 is a broader superset that adds features such as unquoted keys and single-quoted strings. A file that uses those features is not JSONC, and a JSONC parser may reject it.

Which format suits your file

The table compares the two formats on the criteria that usually decide the choice.

Criterion | JSON | JSONC
Comments | Not allowed | Line and block comments allowed
Trailing commas | Not allowed | Depends on the parser
Formal standard | Yes (RFC 8259, ECMA-404) | No single universal specification
Parser support | Built into most languages and platforms | Only tools that explicitly support it
Typical use | Data exchange between programs, API payloads, stored data | Human-edited configuration files read by a tool that accepts comments
Editability | Readable, but explanations must live outside the file | Explanations can sit next to the values they describe
Conversion to the other format | Valid JSON is generally valid JSONC as-is | Requires stripping comments and trailing commas; comments are lost

Choose JSON when another program will consume the file, when the data travels over a network, or when you do not control every tool that will read it. Its strictness is what makes it portable.

Choose JSONC for configuration that people edit by hand, and only when the program reading it documents comment support. Comments let you record why a value is set, which options are temporary, and what alternatives exist, without keeping a separate notes file in sync.

If a file must be both human-annotated and consumed by strict parsers, keep a JSONC source and generate plain JSON from it as a build step. The comments stay in the source, and the output works everywhere.

Converting between the two

Converting JSON to JSONC needs no changes, because a valid JSON document contains nothing a JSONC parser should reject. Converting JSONC to JSON means removing every comment and any trailing commas. That direction is one-way: the comments are discarded and cannot be recovered from the JSON output.

Removing comments is not a simple find-and-replace. Two slashes inside a string value, such as a URL, are data and must be kept. A converter needs to recognize string boundaries, which is why a JSONC-aware parser or formatter is safer than a regular expression. After converting, run the result through a strict JSON validator to confirm it parses.

Will the file work where you need it?

Comments are ordinary text characters, so they survive copying, pasting and version control without any special handling. The risk is the destination. Pasting JSONC into a place that expects JSON, such as an API request body, a strict JSON parser or a field labeled as JSON, typically causes a parse error rather than silently ignoring the comments. The built-in JSON parsers in many programming languages reject comments in this way.

Before using a JSONC file outside the tool it was written for, check these points:

  • Does the receiving tool's documentation state that it accepts comments? If not, convert to plain JSON first.
  • Does it accept trailing commas? Remove them if this is unclear.
  • Is your validator set to the right mode? A strict JSON validator will report every comment as an error, which is correct for JSON but misleading for a JSONC file.
  • Does your formatter preserve comments? Some formatters parse to data and reprint it, which removes them. Test on a copy first.
  • Is the file extension meaningful to your tools? Editors and linters may choose JSON or JSONC rules based on the extension or on per-file settings.

For readability, including for people using screen readers, comments are plain text read in order with the rest of the file. They can make a configuration file easier to understand, provided they are kept short and placed next to the values they explain. This guide has no tested data on how specific assistive technologies announce comment markers, so check with the tools your readers use if that matters for your audience.

Handling sensitive files

Configuration files often contain API keys, tokens, passwords, internal hostnames or personal data, and comments sometimes include notes about them. Pasting such a file into an online formatter or validator sends its full contents to an external service, where it may be logged or retained. Prefer a formatter or validator that runs locally, such as one built into your editor or a command-line tool. If you must use an online service, remove or replace sensitive values first, including any mentioned in comments.

Summary

JSONC is JSON plus comments, and in some tools plus trailing commas. It suits hand-edited configuration read by tools that document support for it. JSON suits everything that must be exchanged, validated strictly or read by tools you do not control. When in doubt, keep plain JSON at the destination and check the receiving tool's documentation before sending it anything with comments.