{}JSONLint.app

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.

Common Mistakes & Pro Tips

  • Comments are removed, not relocatedBoth // line comments and /* block */ comments are stripped to produce strict JSON, because the JSON spec allows no comments at all. There's nowhere to preserve them, so document important notes in actual data fields if you need them to survive.
  • Trailing commas are the most common JSONC-only featureJSONC tolerates a comma after the last element in an array or object ([1, 2, 3,]), which strict JSON rejects. Converting removes that dangling comma so the output parses with a standard JSON.parse.
  • Don't strip comment-like text inside stringsA proper JSONC parser must not remove // or /* when they appear inside a string value, such as a URL "https://example.com". Naive find-and-replace breaks these, so the conversion has to be string-aware to leave "http://..." intact.
  • JSONC is still mostly JSON — single quotes aren't allowedJSONC (as used by VS Code and TypeScript config files) adds comments and trailing commas only; it does not permit single-quoted strings, unquoted keys, or other JSON5 relaxations. If your file uses those, it's JSON5, not JSONC, and needs a different converter.

Frequently Asked Questions

What is JSONC and how does it differ from JSON?

JSONC is "JSON with Comments," the variant used by Visual Studio Code settings and tsconfig.json files. It extends JSON with // and /* */ comments and tolerates trailing commas, but is otherwise identical to standard JSON. Converting to JSON makes the file parseable by any strict JSON consumer.

How do I strip comments from a config file?

Paste the JSONC content and the converter removes all line and block comments and any trailing commas, returning valid JSON. The data structure and values are unchanged — only the comments and dangling commas disappear. The result can then be fed to JSON.parse or any strict parser.

Will comments inside string values be removed by mistake?

No. The conversion is string-aware, so // and /* sequences that appear inside quoted strings (like a URL or a regex) are preserved. Only comment syntax outside of strings is stripped.

Does it handle trailing commas?

Yes. Trailing commas after the final array element or object property are removed during conversion, since strict JSON forbids them. This is one of the two main reasons a JSONC file fails JSON.parse, the other being comments.

Can I convert JSON5 with single quotes and unquoted keys here?

Not reliably. JSONC supports only comments and trailing commas, whereas JSON5 additionally allows single quotes, unquoted keys, hex numbers, and more. If your file uses those JSON5 features, you'll need a JSON5-specific tool rather than a JSONC converter.

Is my config file uploaded during conversion?

No. Comment and comma stripping happens entirely in your browser, so your tsconfig, settings, or other config files never leave your device. That keeps any embedded paths, tokens, or internal URLs private.