JSONC to JSON Converter

Convert JSON with comments (JSONC) or JSON5 to standard JSON. Perfect for preparing config files for production or API use.

433 chars
Loading...
Loading...

JSONC/JSON5 Features We Support

Single-line comments
// comment
Multi-line comments
/* ... */
Trailing commas
{"a": 1,}
Unquoted keys
{key: "value"}
Single quotes
{'a': 'b'}
Hexadecimal numbers
0xFF

What is JSONC?

JSONC (JSON with Comments) is an extension of JSON that allows JavaScript-style comments. It's widely used in configuration files where documentation is helpful:

  • VS Code settingssettings.json, tasks.json
  • TypeScript configtsconfig.json
  • ESLint config.eslintrc.json
  • And many more...

Standard JSON parsers don't support comments, so you need to strip them before using the data in production code or sending to APIs.

JSONC vs JSON5 vs Standard JSON

FeatureJSONJSONCJSON5
Single-line comments (//)
Multi-line comments (/* */)
Trailing commas
Unquoted keys
Single quotes
Hex numbers
Multi-line strings

This tool converts both JSONC and JSON5 to standard JSON, handling all the features listed above.

Comment Syntax

Single-line comments

Start with // and continue to the end of the line:

{
  "port": 3000, // Server port
  "host": "localhost" // Only for development
}

Multi-line comments

Enclosed in /* */, can span multiple lines:

{
  /*
   * Database configuration
   * Update these values for production
   */
  "database": {
    "host": "localhost",
    "port": 5432
  }
}

Why Remove Comments?

While comments are great for documentation, they cause problems in certain contexts:

  • JSON.parse() fails — JavaScript's built-in parser doesn't support comments
  • APIs reject them — Most REST APIs expect standard JSON
  • Smaller payloads — Comments add bytes that aren't needed at runtime
  • Interoperability — Other languages' JSON parsers don't support comments

Programmatic Conversion

JavaScript/Node.js

// Option 1: Use jsonc-parser (VS Code's parser)
import { parse } from 'jsonc-parser';

const jsonc = '{"a": 1} // comment';
const result = parse(jsonc);

// Option 2: Use strip-json-comments
import stripJsonComments from 'strip-json-comments';

const json = stripJsonComments(jsonc);
const data = JSON.parse(json);

// Option 3: Use json5 library
import JSON5 from 'json5';

const data = JSON5.parse('{"a": 1,}'); // handles trailing commas too

Python

# Using pyjson5 library
import pyjson5

data = pyjson5.load(open('config.json5'))

# Or commentjson for just comments
import commentjson

data = commentjson.load(open('config.jsonc'))

Command Line

# Using Node.js
npx strip-json-comments-cli config.jsonc > config.json

# Using jq (after stripping comments manually)
cat config.json | jq '.'

Best Practices

  • Use JSONC for config files — Comments make configs self-documenting
  • Convert before deployment — Strip comments in your build process
  • Don't store secrets in comments — They're still in the file!
  • Keep comments concise — Long comments belong in external docs

Common Use Cases

VS Code Settings

VS Code's settings.json supports JSONC, but if you need to process these settings programmatically, you'll need to strip the comments first.

TypeScript Configuration

tsconfig.json supports comments, but tools that read it programmatically might not. Use this converter to create a comment-free version.

API Requests

If you're copying configuration from a JSONC file to use in an API request, this tool removes the comments so the request doesn't fail.

Related Tools

Frequently Asked Questions

Why doesn't JSON support comments?

Douglas Crockford (JSON's creator) intentionally excluded comments to prevent them from being used for parsing directives, which would complicate the format. JSON was designed to be simple and unambiguous.

Can I add comments back after conversion?

No — once comments are stripped, the information is lost. Keep your source JSONC file and only convert to JSON when needed for deployment or APIs.

Is JSONC the same as JSON5?

No. JSONC only adds comments and trailing commas. JSON5 is a larger superset that also allows unquoted keys, single quotes, hex numbers, and multi-line strings. This tool handles both.

Will this tool modify my data?

Only comments and trailing commas are removed. The actual data values remain unchanged. However, formatting (whitespace, indentation) may change.