FileExamples
ErrorJSON · .json

JSON with Comments — Why Comments Break JSON Parsers

A JSON file containing JavaScript-style comments (// or /* */). Comments are not part of the JSON specification despite being common in config files.

Why It Fails

Douglas Crockford intentionally excluded comments from JSON to prevent misuse as a processing directive. JSON parsers treat comment characters as invalid syntax. JSONC and JSON5 are alternative formats that support comments.

Broken Example

{
  // This is a comment
  "name": "Alice",
  /* Multi-line
     comment */
  "age": 30
}

Expected Error Behavior

JSON.parse() throws SyntaxError. Config tools like VS Code use JSONC internally but standard JSON APIs reject comments.

Affected Software

JSON.parse()All standard JSON parsersREST APIsDatabase JSON columns

How to Fix

Remove all comments before parsing. Use JSONC or JSON5 format if comments are needed. Strip comments with a preprocessor.