JSON, JSONC, and JSON5 look similar, but they are not interchangeable. Mixing them is a common cause of parser errors.
{
// JSONC / JSON5 allow comments in some tools
name: 'ToolGarden',
tags: ['json', 'tools'],
}Core Differences
| Format | Standard JSON? | Main trait |
|---|---|---|
| JSON | Yes | Strict and widely supported for APIs and data exchange |
| JSONC | No | Common for config files, allows comments, stays close to JSON |
| JSON5 | No | More JavaScript-like, allows single quotes, trailing commas, unquoted keys, and more |
Why Do APIs Usually Require Standard JSON?
APIs, databases, queues, and third-party platforms need data that can be parsed consistently across languages such as JavaScript, Java, Go, Python, and Rust. Standard JSON has fewer rules and fewer ambiguous edge cases.
- Comments are not data and have no shared meaning in API payloads.
- Trailing commas, single quotes, and unquoted keys are supported inconsistently across parsers.
- NaN and Infinity are not standard JSON values and are often rejected by backends.
- Config files can optimize for humans; API payloads should optimize for stable machine parsing.
Why Can tsconfig.json Contain Comments?
Many developers first notice comments in tsconfig.json and wonder why a .json file can contain //. TypeScript reads that file with JSONC-like rules, which is not the same as ordinary JSON parsing for API payloads.
| File or case | Common format | Can you send it to a normal API? |
|---|---|---|
| tsconfig.json | JSONC-style config | Do not assume so |
| VS Code settings.json | JSONC-style config | Do not assume so |
| package.json | Standard JSON | Usually yes |
| API request body | Standard JSON | Should be standard JSON |
How to Convert JSONC / JSON5 to Standard JSON
- Parse the loose syntax and confirm that a JSONC or JSON5 parser understands it.
- Remove comments and trailing commas, and quote unquoted keys.
- Convert single-quoted strings to double-quoted JSON strings.
- Check for unsupported values such as NaN, Infinity, and undefined.
- Validate the final output with a strict JSON validator.
Which One Should You Use?
- For API requests and responses, use standard JSON.
- For human-maintained config files, JSONC can work when the toolchain supports it.
- For JavaScript-like authoring convenience, JSON5 can be useful but is not accepted by ordinary JSON APIs.
- Before sending data to a backend, database, or third-party system, convert to standard JSON.