跳到主要内容
uencoder

JSONC (JSON 具有 Comments) Specification

JSONC 是 JSON 具有行 和阻止 comments, used 通过 VS Code 和 TypeScript 配置 files.

Comment Support

JSONC extends JSON with // line comments and /* block comments */. No other syntax changes are made; trailing commas and unquoted keys remain disallowed. The format is used by VS Code settings, tsconfig.json, and other configuration files. JSONC parsers strip comments before standard JSON parsing. The format is a minimal, pragmatic extension for configuration.

line comments
// style
VS Code settings
block comments
/* */ style
tsconfig.json
no other changes
Strict JSON otherwise
minimal extension

Parsing Strategy

Most JSONC implementations preprocess input to remove comments before JSON.parse. TypeScript provides native JSONC parsing via tsconfig APIs. VS Code has a built-in JSONC parser with schema validation. The format is not suitable for data interchange due to non-standard parsers. For programmatic config, JSONC offers the simplest extension over JSON.

preprocess
Strip then parse
common approach
TypeScript
Native parse API
ts.readConfigFile
VS Code
Built-in parser
jsonc-parser

相关工具

参考链接