What Is JSONC? JSON vs JSON5 vs JSONC Explained
Explore what JSONC (JSON with Comments) is, how it compares with JSON and JSON5, where it is used in tools like VS Code, and how to choose the right format.
Why Do You See Files Ending in .jsonc?
If you configure VS Code, author TypeScript configuration files (tsconfig.json), or maintain modern DevOps infrastructure, you have undoubtedly encountered .jsonc files.
At first glance, JSONC looks identical to standard JSON. The defining difference is that JSONC permits comments (both // single-line and /* */ block comments), transforming cryptic configuration files into human-friendly, self-documenting assets.
In this guide, we break down what JSONC is, how it compares against JSON and JSON5, where it thrives, and how to safely convert between them.
What Is JSONC? (JSON with Comments)
JSONC stands for JSON with Comments. It is a specification designed to solve the biggest annoyance developers face when authoring configuration files in standard JSON: the total ban on comments.
1{2 "name": "John",3 "age": 304}1{2 // User information (SyntaxError in Standard JSON!)3 "name": "John",4 "age": 305}In a JSONC-aware parser, comments are simply treated as trivia/whitespace and safely ignored during data extraction, leaving the underlying key-value data intact.
JSONC in Action: Practical Syntax
JSONC supports both single-line and multi-line comments anywhere whitespace is allowed:
1{2 // Single-line comment explaining this setting3 "name": "John"4}1{2 /*3 Multi-line block comment:4 Explains the entire user schema5 */6 "name": "John"7}1{2 // Application configuration3 "name": "My App",4 "version": "1.0.0",56 // Server settings7 "server": {8 "port": 3000,9 "host": "localhost"10 }11}Why Was JSONC Created? (Machine vs. Human Needs)
Douglas Crockford purposefully removed comments from the original JSON specification in 2001 to prevent developers from using comments as parsing directives (similar to what happened with HTML comments).
This worked wonderfully for machine-to-machine APIs. But as modern development shifted toward declaring project configs in JSON (like tsconfig.json, VS Code settings.json, and npm configs), developers struggled without the ability to document settings.
1{2 "server": {3 "port": 3000,4 "timeout": 50005 },6 "database": {7 "host": "localhost",8 "port": 54329 }10}Teammates must guess what timeout: 5000 means (seconds? milliseconds?).
1{2 // HTTP server configuration3 "server": {4 "port": 3000,5 "timeout": 50006 },78 // Local database configuration9 "database": {10 "host": "localhost",11 "port": 543212 }13}Comments make it instantly clear that 5000 is milliseconds for the HTTP server.
JSONC vs. JSON5: Understanding the Crucial Difference
One of the most common points of confusion in the developer community is comparing JSONC with JSON5. Both allow comments, but their scope is vastly different:
1{2 // User configuration3 "name": "John",4 "age": 305}Keeps strict JSON rules: double quotes on all keys and strings. Only adds comments.
1{2 // User configuration3 name: 'John',4 age: 30,5}Allows comments PLUS unquoted keys, single quotes, trailing commas, and hex numbers.
JSON vs. JSONC vs. JSON5: 3-Way Feature Comparison
| Feature | Standard JSON | JSONC | JSON5 |
|---|---|---|---|
| Primary Purpose | Strict data exchange & APIs | Human-readable configuration | Relaxed human-friendly data/config |
| Comments (// and /* */) | ❌ Not allowed | ✅ Supported | ✅ Supported |
| Single-Quoted Strings ('text') | ❌ Double quotes only | ❌ Double quotes only | ✅ Allowed |
| Unquoted Property Keys | ❌ Must use double quotes | ❌ Must use double quotes | ✅ Allowed for valid identifiers |
| Trailing Commas | ❌ Syntax error | ⚠️ Tool-dependent | ✅ Fully supported |
| Native JSON.parse() Compatible | ✅ 100% standard | ❌ Requires comment stripping | ❌ Requires JSON5 parser |
| Standard File Extension | .json | .jsonc / .json | .json5 |
| API Wire Format Usage | ⭐⭐⭐⭐⭐ De-facto standard | ⚠️ Risky (breaks strict clients) | ⚠️ Risky (breaks strict clients) |
Does JSONC Allow Trailing Commas?
This is the single most common cause of confusion. Because JSONC is not formalised by an IETF RFC standard, different tooling handles trailing commas differently:
1{2 "name": "John", // Trailing comma: accepted by some JSONC tooling, invalid in strict JSON3}.jsonc files, but smaller CLI parsers may throw syntax errors. If your configuration must be consumed across multiple languages or tools, avoid trailing commas or use JSON5 instead.Where Is JSONC Used in Practice?
JSONC is heavily embraced across modern frontend and developer tooling:
User settings (settings.json), keybindings (keybindings.json), and extension launch configs.
tsconfig.json natively permits comments so you can annotate compiler target and module options.
Linter configs, rule overrides, and project formatting configurations.
1{2 // Controls the editor font size in pixels3 "editor.fontSize": 14,45 // Automatically format files upon saving6 "editor.formatOnSave": true,78 // Default tab size9 "editor.tabSize": 210}How to Convert JSONC to Standard JSON
When building production applications, configuration files with comments must often be sanitized into standard RFC 8259 JSON before being sent over HTTP or passed into strict libraries:
1{2 // Production server configuration3 "host": "localhost",4 "port": 30005}1{2 "host": "localhost",3 "port": 30004}In Node.js, you can use packages like jsonc-parser (authored by the VS Code team) or strip-json-comments to strip comments before calling JSON.parse().
5 Common JSONC Mistakes That Break Builds
1. Sending JSONC to a Strict JSON API
Comments in HTTP request bodies cause JSON.parse() in backend engines (Express, Django, Spring) to crash with SyntaxError: Unexpected token /.
2. Assuming .jsonc Works Automatically Everywhere
The .jsonc file extension informs IDEs like VS Code to enable syntax coloring, but runtime libraries still need an explicit JSONC parser.
3. Treating JSONC as JSON5
JSONC strictly demands double quotes ("key": "val") and rejects unquoted keys or single quotes. Only JSON5 permits full JavaScript-style syntax.
4. Relying on Trailing Commas in JSONC
Some tools (like VS Code) tolerate trailing commas in .jsonc, while others strictly reject them. Keep syntax trailing-comma-free for safety.
5. Expecting Comments to Persist in Parsed Data
Comments are stripped away during parsing. If you parse JSONC and serialize it back out with JSON.stringify(), all comments will be lost.
Frequently Asked Questions
JSON for Machine APIs • JSONC for Project Configs • JSON5 for Relaxed Scripts
Never let formatting syntax slow down your team. Use PlayWithJSON's free browser tools to format, clean, convert, and validate any JSON dialect in seconds.