October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk12 min

How to Convert JSONC Files to Valid JSON

Parse JSONC with a dialect-aware parser, check its errors, and serialize the data as strict JSON. Learn how to handle trailing commas and avoid unsafe comment stripping.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Parse the file with a JSONC-aware parser, stop if it reports errors, then serialize the parsed value with a standard JSON serializer. In Node.js, Microsoft’s jsonc-parser can do this. Set its trailing-comma option deliberately: JSONC supports comments, but trailing commas are not required by the JSONC specification and parser defaults differ.

What conversion does—and what it does not

JSONC is JSON extended with JavaScript-style comments: single-line // comments and block /* ... */ comments can appear where whitespace is allowed. Strict JSON does not allow those comments, so a strict JSON consumer may reject a JSONC file. The JSONC specification says comments are ignored during parsing and that removing them must preserve the JSON value representation. It also says, “Comments provide context alongside the data, but they MUST NOT affect consumption.”

As an Amazon Associate I earn from qualifying purchases.

A reliable conversion therefore has two stages: interpret the source using the intended JSONC rules, then write the resulting data using a strict JSON serializer. The output contains the data values, not the comments or the original formatting. If comments are important to maintainers, keep the JSONC source as well or document the explanations separately; comments are not part of the JSON value.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

It helps to distinguish conversion from editing. Conversion is not simply changing the filename from .jsonc to .json, nor is it a promise that the document’s comments can be carried into strict JSON. The converter reads the source as text, recognizes the syntax of the chosen dialect, builds the underlying value, and writes that value in JSON syntax. The result can preserve the data representation while looking different: indentation, spacing, and line breaks may be normalized by the serializer.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

The JSONC specification recommends the .jsonc extension. An extension can make a file’s intended format clearer to people and tools, but it does not by itself make the contents valid for a strict JSON parser. The receiving program’s expected format is decisive: if it accepts only strict JSON, supply the serialized output rather than the commented source.

Convert a JSONC file with Node.js

Install the jsonc-parser package in your Node.js project, then use a parser and serializer. The example below allows trailing commas for input files that use them. It checks the parser’s error list before writing anything, because a fault-tolerant parser may return a partial value even when the input has errors.

import fs from 'node:fs';
import { parse } from 'jsonc-parser';

const input = fs.readFileSync('config.jsonc', 'utf8');
const errors = [];
const value = parse(input, errors, { allowTrailingComma: true });

if (errors.length > 0) {
  throw new Error(`Invalid JSONC: ${JSON.stringify(errors)}`);
}

fs.writeFileSync('config.json', JSON.stringify(value, null, 2) + 'n');

The parser package documents parsing JSON with comments and checking the error list to determine whether the input was valid. Confirm the function signature against the version installed in your project; the package documentation is available on npm and in its README.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The example reads the source as UTF-8 text, passes that text to the parser, and supplies an array for reported errors. The array is the important checkpoint: do not treat the existence of a returned value as proof that the whole document was valid. If errors are present, stop the conversion and correct the source or the parser options before producing the final file. The example throws before the write call, so it does not knowingly publish a partial parse as a completed conversion.

Once parsing succeeds, JSON.stringify(value, null, 2) serializes the value with two spaces of indentation. The final n adds a newline after the serialized document. These are output-format choices, not JSONC requirements; use the standard serializer’s options that fit your project’s formatting convention. Writing to config.json rather than replacing config.jsonc also leaves the commented source available for review or later edits.

Choose whether trailing commas are allowed

The JSONC specification treats trailing-comma support as optional, and the reference jsonc-parser setting allowTrailingComma is false by default. If your source uses a trailing comma, explicitly enable it as in the example. If your input policy should reject trailing commas, omit the option or set it to false. A parser accepting comments does not automatically mean it accepts every other extension.

Make this a deliberate policy decision rather than changing parser settings only until a file happens to pass. If the files in your workflow are meant to follow a stricter JSONC subset, leaving trailing commas disallowed can flag them for correction. If your existing JSONC files intentionally contain trailing commas, enabling the option lets the parser read that dialect. Whichever policy you choose, apply it consistently to the files being converted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not assume that the word “JSONC” guarantees identical behavior across editors, libraries, or applications. The specification does not require universal trailing-comma support, and VS Code’s JSON-with-comments mode has configuration-specific behavior. If a file works in one editor but fails in a conversion script, compare their accepted syntax and settings rather than assuming either tool is necessarily using the same dialect.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Check the generated file

After conversion, optionally parse the output with a strict JSON parser or run the receiving application’s normal validation. This catches problems at the boundary where the file will actually be consumed. Use a separate output path, as shown, until you have verified the result; that preserves the original JSONC file, including its comments.

There are two distinct checks here. First, the JSONC parser’s diagnostics tell you whether it could interpret the source according to the rules and options you selected. Second, a strict parser or the actual consumer can verify that the serialized file is accepted where it will be used. The latter matters when the output is part of a larger workflow, because syntactic validity does not establish that an application-specific configuration is semantically acceptable.

If the strict check fails, keep the source and inspect the generated file before replacing or distributing it. The parse-and-serialize workflow should remove comments and write valid JSON syntax, but validation is a useful independent check that the file at the destination is the one the consumer can read. Do not suppress source parse errors simply to force output: a partial value can omit or misrepresent data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Repeatable conversion for multiple files

For a repeatable workflow, treat the parser option, error check, serializer settings, and destination handling as part of the conversion policy. A script should apply the same dialect rules to every input, stop on parsing errors, and write output only after a successful parse. That makes failures visible instead of silently producing files that differ according to which editor or tool happened to touch them.

Keep the original JSONC files unchanged until the output has passed the checks required by the receiving application. If a conversion is part of a build or deployment process, use that process’s normal validation step as the final acceptance test. The sources cited here document parser capabilities and package conversion patterns; they do not specify a universal command-line converter or a one-size-fits-all validation command.

Go option

For Go workflows, the tidwall/jsonc package documents a jsonc.ToJSON conversion function. Its documented pattern is to convert JSONC text to JSON before passing the result to Go’s standard JSON library. Check the package’s current documentation for the exact API in the version you install, and validate the converted output through the application’s normal JSON decoder.

This route is useful when the conversion belongs in a Go program rather than a Node.js script. The package’s ToJSON function handles the JSONC-to-JSON conversion step; the standard library decoder can then be used in the application’s normal workflow. As with Node.js, do not assume that a conversion call by itself replaces validation. Check current package behavior, handle errors as appropriate for the installed API, and confirm that the result can be decoded and used by the target program.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The two language options serve similar goals but fit different environments. Choose jsonc-parser when you need the Node.js parser and its diagnostics, and choose tidwall/jsonc when your conversion is in Go. In either case, verify the version’s documented interface and the syntax options relevant to your files. The available documentation does not establish that the packages accept precisely the same extensions in every configuration.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Choose the method that matches your input

Approach Use it when Important consideration
Parse with jsonc-parser, then serialize You are converting in Node.js and want parser diagnostics. Check errors and deliberately configure trailing-comma handling. See the package README.
Convert with tidwall/jsonc’s ToJSON You are working in Go. Check current package behavior and validate the result in your application. See the package documentation.
Strip comments You need to retain much of the source text or formatting. Comment removal alone does not necessarily remove trailing commas or detect malformed input. See the JSONC specification and parser documentation.
Use a JSON5 parser The input is intentionally JSON5 rather than JSONC. JSON5 permits syntax beyond JSONC, so use it only when that broader dialect is intended. See the JSON5 specification.

For most conversions where the original layout does not need to survive, parsing and serializing is the clearest choice. It gives you a parsed value to write as strict JSON and a place to inspect parse errors. Comment stripping is a narrower option: it may leave existing whitespace and much of the text intact, but it does not perform the same complete parse-and-write operation.

The practical trade-offs are the language available in your workflow, the exact syntax your files contain, the quality of diagnostics you need, and whether preserving source formatting matters. If comments are valuable to the people maintaining the file, retaining the JSONC source is often simpler than trying to preserve comments in an output format that does not include them. If the consumer requires strict JSON, prioritize a valid serialized output over visual similarity to the source.

Common conversion problems

A strict JSON parser rejects the source

This is expected if the file contains comments: comments are not valid strict JSON syntax. Parse it first with a JSONC-aware parser, then serialize the resulting value as JSON.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Changing only the extension will not resolve a syntax mismatch. Check that the source is intended to be JSONC and that the converter is configured for any optional syntax the file uses. A strict parser is appropriate for checking the final output, not for interpreting a source file that intentionally includes JSONC comments.

The parser rejects a trailing comma

Check the parser’s trailing-comma setting and the dialect you intend to accept. In jsonc-parser, trailing commas are disallowed by default. Enable allowTrailingComma only if the source files are meant to permit them; otherwise, remove the comma from the source and keep the stricter setting.

Remember that permitting trailing commas is not the same as permitting arbitrary syntax. If the parser still reports errors after you select the intended comma policy, examine the input and error list; do not assume that all JSONC tools share the same options or defaults.

Removing comments leaves invalid JSON

Deleting comment text does not validate the remaining document. A trailing comma or another syntax error can still make it invalid. Prefer parse-and-reserialize when you do not need the original formatting; inspect parser errors and validate the output with the receiving application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Microsoft’s jsonc-parser exposes stripComments, which can be useful when keeping much of the original text is important. But comment stripping has a limited job: removing comments is not proof that the result is valid strict JSON. It does not automatically resolve optional trailing commas or unrelated syntax problems. If output validity is the requirement, follow comment removal with appropriate parsing and validation, or use the parse-and-reserialize workflow.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

A regular expression damages a string

A broad search-and-replace for // or /* ... */ can mistake those characters inside a quoted string for comments. Use a syntax-aware parser or scanner rather than removing comment markers with a general regular expression. This follows from the fact that comment recognition depends on the document’s syntax, which is why JSONC tooling provides a scanner and parser.

For the same reason, matching comment-looking characters without tracking whether the parser is inside a string is unsafe. A URL or other string value can contain slash characters that are data, not a comment. A parser understands the context in which a marker appears; a broad textual replacement does not. If you need to preserve much of the source, use a syntax-aware comment stripper and still validate the resulting text.

Nested block comments do not parse

JSONC block comments are not nested: the first closing */ ends the comment. If a block comment contains another opening marker, rewrite the comment rather than expecting the parser to treat it as nested.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, explanatory text inside a block comment should not itself rely on a second block-comment pair remaining inactive. Use a simpler comment or separate the explanation. This is a JSONC syntax boundary, not a setting to turn on in the conversion script.

The comments disappear from the output

That is normal for conversion to JSON. Comments provide context in the source but are not part of its parsed data value. Keep the JSONC source or move essential explanations into documentation or explicit data fields if readers need them after conversion.

Do not expect a JSON serializer to reconstruct where comments appeared or what they said. The specification treats comments as context that must not affect consumption, and the parsed value therefore does not include them. Retain the source file as the human-maintained version if its comments are important, and generate strict JSON as a derived artifact when needed.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep JSONC and JSON5 distinct

JSONC means JSON with comments; it should not be treated as a synonym for JSON5. JSON5 supports comments and trailing commas but also adds other syntax extensions. If the source is meant to follow JSONC, choose a JSONC parser and configure its optional trailing-comma behavior rather than silently accepting a broader language. If it is intentionally JSON5, use a JSON5 parser and confirm that the consumer expects the resulting JSON data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This distinction matters when selecting a converter. A JSON5 parser may accept inputs that are not part of the JSONC dialect, which can hide a mismatch between the actual file format and the format your team expects. Conversely, a JSONC parser configured to reject trailing commas may flag a file that a JSON5 parser accepts. Identify the intended dialect first, then use matching parser rules instead of selecting a more permissive tool simply because it accepts the file.

Once the source has been parsed as its intended format, the output can still be ordinary JSON: serialize the parsed value with a standard JSON writer, then check it with a strict parser or the receiving application. That final step is about the data output, not about preserving source comments or extensions.

Frequently Asked Questions

Can I convert a JSONC file by renaming it to .json?

No. Renaming does not remove comments or convert the document’s syntax. Parse the file with a JSONC-aware parser, check for errors, and serialize the value as strict JSON.

Does every JSONC parser accept trailing commas?

No. The JSONC specification makes trailing-comma support optional. Microsoft’s jsonc-parser disallows them by default; enable allowTrailingComma only when your input policy permits them.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Will the converted JSON keep its comments and formatting?

A parse-and-reserialize conversion preserves the parsed data values, not comments or the original layout. Keep the JSONC source if its comments or formatting matter to maintainers.

Is it safe to remove JSONC comments with a regular expression?

A broad expression can mistake comment markers inside quoted strings for actual comments. Use a syntax-aware parser or scanner, and validate the result because removing comments alone does not guarantee valid JSON.

When should I use JSON5 instead of a JSONC parser?

Use a JSON5 parser when the input is intentionally JSON5. JSON5 includes comments and trailing commas but also permits other syntax extensions, so it is not interchangeable with JSONC.

The Bottom Line

To make strict JSON from JSONC, parse with a tool configured for the source dialect, stop on parser errors, then serialize the parsed value with a standard JSON writer. Decide explicitly whether trailing commas are allowed, keep the original file if comments matter, and validate the output with the intended consumer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.