JSON & Schema

JSON Comments: Are Comments Allowed in JSON?

Strict JSON has no comment syntax. A parser that accepts // or /* ... */ is processing a different dialect or applying a non-standard extension.

Published

The short answer: strict JSON has no comments

The // token is outside the JSON grammar and causes a strict parse error.

{
  // API timeout
  "timeout": 5000
}

Why JSON.parse and strict tools reject comments

Strict grammar makes interchange predictable across parsers. A tolerant editor does not prove that an API or standard JSON parser will accept the same file.

The _comment property workaround

This is valid JSON, but _comment is real data. It can affect schemas, signatures, storage, and consumers.

{ "_comment": "API timeout in ms", "timeout": 5000 }

JSONC and JSON5

JSONC and JSON5 are distinct formats with additional syntax. Use the correct extension, parser, and contract instead of labeling them strict JSON.

JSON Schema $comment

$comment is a JSON Schema keyword inside a schema document. It is not general comment syntax for arbitrary JSON data.

Why some editor config files look like JSON with comments

The owning application may define the file as JSONC or use a tolerant parser. That support does not transfer automatically to another tool.

Why a minifier should not delete comments silently

Removing non-standard syntax is a format conversion with semantic risk, not ordinary whitespace minification. A strict minifier should report the invalid input.

Common mistakes

  • Assuming editor highlighting proves strict validity.
  • Sending commented JSON to a strict API.
  • Using a _comment property where additional fields are forbidden.
  • Calling JSONC output JSON without documenting the parser.

Try commented JSON in JSON Minifier

Run the invalid and valid examples to observe the actual parser result rather than relying on hard-coded error wording.

Try the example

Observe a strict JSON comment error

A // comment makes this document invalid for a strict parser.

{
  // API timeout
  "timeout": 5000
}

Expected result: The minifier reports a real parser error and does not silently remove the comment.

Try the example

Use a real data property deliberately

The _comment member is valid JSON data, not comment syntax.

{
  "_comment": "API timeout in ms",
  "timeout": 5000
}

Expected result: The JSON validates and _comment remains in the minified output.

See the parser boundary

Test strict JSON

Compare a commented document with a valid data-property alternative.

Open in JSON Minifier →