How to use the jsonc to json converter
- Paste your JSONC text into the input area.
- The tool automatically strips
//and/* */comments and removes trailing commas. - Review the resulting strict JSON in the output area.
- Copy the cleaned JSON for use in your application or configuration file.
What is JSONC?
JSONC stands for JSON with Comments. It is a relaxed superset of standard JSON that allows developers to add single-line comments starting with // and multi-line block comments wrapped in /* */. Many configuration files, such as tsconfig.json, settings.json in Visual Studio Code, and various build tool configurations, use this format because plain JSON forbids comments entirely.
While convenient for humans reading configuration files, most programming languages and APIs expect strict JSON. Passing JSONC directly to JSON.parse() in JavaScript or equivalent parsers in other languages will throw a syntax error. Converting jsonc to json resolves this mismatch by removing the non-standard elements before parsing.
How the conversion works
The converter processes the input character by character using a simple state machine. It tracks whether the current position is inside a double-quoted string, a single-line comment, or a multi-line comment. When inside a string, characters like / and * are treated as literal text, ensuring URLs such as "https://example.com" remain untouched. Escape sequences like \" inside strings are handled correctly so they do not prematurely close the string context.
After stripping comments, the tool addresses trailing commas. A trailing comma occurs when a comma appears immediately before a closing bracket ] or brace }, ignoring whitespace. The converter uses a regular expression to find these patterns and removes the offending commas. Finally, the cleaned text is passed through JSON.parse() to validate the structure. If validation fails, a clear error message indicates the line and column of the problem.
Common JSONC features handled
A robust jsonc to json conversion must handle several edge cases that trip up naive search-and-replace scripts:
- Comments inside strings: A value like
"path": "C://folder/*file*"contains characters that look like comments but are part of the data. The parser respects string boundaries. - Escaped quotes: Strings containing
\"must not break the string-tracking logic. - Nested trailing commas: Objects and arrays can be deeply nested, each potentially ending with a trailing comma. All levels are cleaned.
- Unicode escapes: Sequences like
\u00e9are preserved exactly as written without modification. - Empty input: An empty string or one containing only whitespace and comments yields no valid JSON value, which triggers an appropriate error rather than crashing.
When to use strict JSON instead
JSONC is excellent for local configuration files edited by humans, but strict JSON remains the standard for data interchange between systems. Web APIs, database storage formats, and inter-service communication protocols universally expect valid JSON without comments or trailing commas.
If you need to transform your cleaned JSON further, related tools can help. You can use json to xml for legacy SOAP services, or convert structured data into code representations like json to go struct, json to java class, or json to c# class for strongly typed applications. For tabular presentations, consider json to html table or json to markdown table.
Reference: JSON vs JSONC syntax
| Feature | JSON | JSONC |
|---|---|---|
Single-line comments (//) | Not allowed | Allowed |
Block comments (/* */) | Not allowed | Allowed |
| Trailing commas | Not allowed | Allowed |
| String values | Double quotes required | Double quotes required |
| Data types | String, number, boolean, null, object, array | Same as JSON |
This table highlights why converting jsonc to json is necessary before sending data over a network or passing it to a strict parser. The structural rules for objects, arrays and primitive values remain identical; only the syntactic sugar differs.
Worked examples
| Example | Input | Result |
|---|---|---|
| Config with comments | JSONC input: { / // Server settings / "host": "localhost", / "port": 8080, / /* Enable debug mode */ / "debug": true, / } | { / "host": "localhost", / "port": 8080, / "debug": true / } |
| Array with trailing comma | JSONC input: [ / "alpha", / "beta", / "gamma", / ] | [ / "alpha", / "beta", / "gamma" / ] |
| Comment inside a string | JSONC input: { / "url": "https://example.com/path?query=1//not-a-comment", / "note": "/* also not a comment */" / } | { / "url": "https://example.com/path?query=1//not-a-comment", / "note": "/* also not a comment */" / } |
FAQ
What is the difference between JSON and JSONC?
JSONC is a superset of JSON that permits single-line comments, multi-line block comments and trailing commas. Standard JSON strictly forbids all three. Most APIs and parsers require standard JSON.
Does this converter remove trailing commas?
Yes. After stripping comments, the tool scans for commas that appear immediately before a closing brace or bracket and removes them, producing valid JSON.
Will comments inside string values be deleted?
No. The parser tracks whether it is currently inside a quoted string. Characters resembling comments within strings are preserved exactly as written.
Is my data sent to a server during conversion?
No. The jsonc to json conversion happens entirely in your browser using JavaScript. Your input text is never transmitted anywhere.
Why does my JSONC file cause errors in my application?
Most runtime environments use strict JSON parsers that reject comments and trailing commas. You must strip these non-standard elements before loading the configuration programmatically.
Can I convert an empty JSONC file?
An empty input or one containing only comments produces no valid JSON value. The tool will return an error indicating that the input is empty or invalid.