JSONC is “JSON with comments,” a practical configuration format used by editors and developer tools. It resembles JSON closely, but a JSONC document is not automatically valid JSON. Treating the names as interchangeable causes confusing failures when a file moves from a tolerant editor into a strict API or runtime.
Strict JSON has a deliberately small grammar
Standard JSON does not include comments or trailing commas. Strings and property names use double quotes, and the only literal names are true, false and null. This limited grammar makes documents portable across languages and parsers.
A .json extension generally signals that strict grammar. When a service accepts a relaxed dialect, its documentation should name the extension or parser behavior explicitly. Do not assume a server accepts comments just because an editor highlights them.
What JSONC adds
JSONC parsers typically accept line comments beginning with // and block comments enclosed by /* and */. Some also accept trailing commas, but that behavior is not universal. The exact dialect is defined by the consuming tool, not by a single internet standard.
Comments are valuable in human-maintained configuration because they record intent. They are less suitable for interchange: downstream systems may strip them, reject them or parse them differently. A JSONC file should therefore be converted before it becomes an API body.
{
// Local development endpoint
"apiUrl": "http://localhost:3000",
"retries": 2
}Choose the format at the boundary
Use JSONC for configuration only when the owning application explicitly supports it. Use strict JSON for HTTP bodies, webhooks, message queues, data exports and files shared across different runtimes. This keeps parser behavior predictable at system boundaries.
If comments contain decisions people need later, move that information into documentation or explicit metadata before conversion. Blindly removing comments can erase operational context even though the resulting JSON remains syntactically valid.
Convert without damaging strings
Do not remove comments with a simple regular expression. Sequences such as // can appear legitimately inside a URL string, while /* may be ordinary text. Use a parser or repair engine that understands string boundaries.
After conversion, parse the strict result and compare key counts or a structural diff with the original parsed JSONC value. That additional check catches accidental changes to arrays, numbers and nested objects.
Practical takeaways
- JSONC is a separate, tool-defined dialect.
- Strict JSON is the safer interchange format.
- Never strip comments with a string-only regular expression.
- Preserve important configuration reasoning outside comments.
How this guide was prepared
JSON Anvil guides are written for working developers, checked against reproducible examples, and reviewed for technical clarity. Tool output is tested locally; readers should still validate behavior in the exact runtime used by their application.