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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Parse the file with a JSONC-aware parser, check for errors, then serialize the parsed value with a standard JSON serializer. This removes comments and produces strict JSON without risking damage from a broad comment-removal regular expression.

What JSONC adds—and what conversion changes

JSONC is JSON extended with JavaScript-style comments: single-line // comments and block /* ... */ comments may appear where whitespace is allowed. Strict JSON does not allow comments, so a strict JSON parser may reject a JSONC file. The JSONC specification recommends the .jsonc extension and says comments must not affect consumption of the data. It describes comments as context alongside data, not as part of the data value.

For example, a JSONC file can explain a setting beside it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
{
  // Address used by the service
  "host": "localhost",
  "port": 8080 /* local development */
}

After parsing and serializing, the result is ordinary JSON:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
{
  "host": "localhost",
  "port": 8080
}

The setting values remain; the comments do not. Parsing and serializing therefore preserves the data values, not explanatory comments or the source file’s original formatting. Keep the JSONC source if readers still need its comments, or store explanations separately. If a receiving system requires strict JSON, comments cannot remain in the converted output because they are not valid JSON syntax.

Trailing commas are a separate compatibility issue: the JSONC specification does not require every implementation to accept them. Some JSONC tools accept trailing commas only when an option is enabled. Decide whether the converter should allow them rather than assuming all JSONC tools behave alike. A file can contain valid comments yet still fail if its trailing-comma style is outside the parser’s configured dialect.

The reliable conversion pattern

A dependable conversion has three distinct stages: parse using the syntax the input is intended to use, inspect diagnostics, and serialize the resulting value with a standard JSON serializer. Each stage addresses a different problem. The JSONC parser understands comments and any deliberately enabled extension, the error check prevents a partial parse from silently becoming output, and serialization writes syntax intended for strict JSON consumers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Read the source file as text. Keep the original JSONC file separate from the output file so the conversion does not overwrite the commented source.
  2. Parse with a JSONC-aware implementation. Configure the parser to match whether trailing commas are accepted in the input.
  3. Stop on reported parse errors. Do not treat the presence of a returned value as proof that the complete file was valid. A fault-tolerant parser may provide a partial structure even when it also reports errors.
  4. Serialize the parsed value as JSON. Use a standard serializer instead of manually deleting syntax from the input.
  5. Optionally validate the output. Parse the serialized file with a strict JSON parser or run the receiving application’s own validation step.

This is different from merely removing comment text. A comment stripper focuses on comments; it does not necessarily check the rest of the syntax or remove a trailing comma. Parse-and-reserialize is the clearer choice when the goal is valid JSON and preserving the source layout is not required.

Convert a JSONC file in Node.js

Microsoft’s jsonc-parser provides a parser for JSON with comments. Its documentation says to inspect the parser’s error list; a returned value alone is not proof that the input was valid. The following pattern opts into trailing commas, then writes readable JSON with a final newline:

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
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');
  1. Make the parser available. Add jsonc-parser to the Node.js project that will run the conversion. Follow the package’s current documentation for setup and the API version used by the project.
  2. Read the source as text. The example reads config.jsonc as UTF-8. It does not try to interpret the file with JavaScript evaluation.
  3. Parse and check diagnostics. Pass an error array to parse and stop if it contains errors. This matters because a fault-tolerant parser can return a partial structure after encountering invalid input. If the error list is nonempty, do not write that value as if it represented the whole file.
  4. Choose trailing-comma behavior. The example sets allowTrailingComma: true. Omit the option or set it to false when trailing commas should be rejected. The reference parser’s documented default is false; see the Microsoft parser README. Making the choice explicit documents the intended input rules instead of relying on a default.
  5. Serialize the parsed value. JSON.stringify(value, null, 2) writes indented JSON, and the appended newline makes the output file end with a line break. The serializer produces JSON syntax from the parsed value; comments and the source’s exact spacing are not carried across.
  6. Validate where the output will be used. If the receiving application has its own validation step, run it on config.json; alternatively, parse the serialized output with a strict JSON parser. This is an additional check of the artifact the next tool will consume.

The exact function signatures should be checked against the installed package version. This example is an implementation pattern, not a claim that it has been executed or tested. The important safeguards are to use the JSONC parser, inspect its errors, make the trailing-comma decision intentionally, and only then write output.

What to change when trailing commas should be rejected

If your input policy permits comments but forbids trailing commas, configure allowTrailingComma as false or omit the option, matching the reference parser’s documented default. Then a trailing comma is not silently accepted under a more permissive setting. If the file fails, inspect and correct the JSONC source rather than loosening the parser merely to produce output. If your files intentionally include trailing commas, the example opts in so that the parser can read that dialect before serializing it as JSON.

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

Why check errors before writing?

The parser’s error list is a validity signal. Some parsers try to recover from malformed input, which can be useful in editing tools but risky in a conversion job. If a converter writes a partial value after a parse error, the output may omit content and still look like a well-formed JSON document. Throwing or otherwise stopping before the write keeps that failed conversion from being mistaken for a successful one. A conversion should produce output only after the input has passed the parser’s checks.

Convert JSONC in Go

The tidwall/jsonc package documents a jsonc.ToJSON conversion function for turning JSONC text into JSON. Use that conversion in the Go workflow, then validate the result with the application’s normal JSON decoder. Check the package’s current documentation for its API and behavior before wiring it into a project.

The same overall sequence applies: provide the source text to the JSONC conversion function, handle any failure according to the package API, and validate the resulting JSON through the decoder or application path that will consume it. The package documentation demonstrates conversion before use with Go’s standard JSON library. Because the exact API and behavior can depend on the package version, consult its current documentation rather than assuming a function signature or error-handling form not shown here.

Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Choose the Go option when conversion belongs in a Go application or tool. If the conversion task already runs in Node.js, the Microsoft parser offers an approach with an exposed parser error list and configurable trailing-comma handling. In either language, the purpose is the same: understand JSONC first, then hand strict JSON to the next step.

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.

Choose the right conversion method

Approach Useful when Trade-off
Parse with Microsoft jsonc-parser, then serialize You want JSONC parsing and diagnostics in a Node.js workflow Check the error list and set trailing-comma behavior intentionally.
Use tidwall/jsonc and ToJSON You are converting within a Go workflow Check the current package documentation and validate the result in the application’s decoder.
Strip comments You need to retain much of the source text or formatting Removing comments alone does not handle trailing commas or validate malformed syntax.
Use a JSON5 parser The input is intentionally JSON5 JSON5 permits syntax beyond JSONC; it is not a drop-in synonym. See the JSON5 specification.

The best method depends on four practical questions:

  • Which language or runtime already owns the task? Use a parser that fits the project: the documented Microsoft parser for a Node.js workflow, or the tidwall package for a Go workflow.
  • Which syntax does the file actually use? Check especially for trailing commas. JSONC implementations do not all share the same settings, and a JSON5 file may contain syntax beyond JSONC.
  • Do you need diagnostics? The jsonc-parser workflow exposes errors to check before output. A conversion tool should not treat a returned value alone as proof of validity.
  • Must comments or formatting survive? Parse-and-reserialize preserves data values, not comments or original formatting. If those matter, retain the original JSONC and choose a different workflow deliberately; do not mistake comment deletion for a full validation step.

For most conversions where the output must be strict JSON, parsing and serializing is preferable to a text-only replacement. It gives the converter a structured value and ensures the output is emitted by a JSON serializer. Comment stripping has a narrower role when retaining much of the source text matters, but it requires separate handling of any other syntax and validation.

Avoid common conversion failures

Do not feed JSONC straight to a strict JSON parser

Comments are outside strict JSON syntax. A strict parser may therefore reject a JSONC source file before it can reach the values you want. Use a JSONC parser first, then pass its serialized output to strict JSON consumers. The strict parser belongs at the output-validation stage, not as a substitute for a JSONC parser on the original input.

Do not remove comment markers with a broad regular expression

The characters // and /* can occur inside quoted strings. A broad replacement cannot reliably tell whether those characters begin a comment or are literal string content, so it can alter actual data. A syntax-aware parser or scanner can distinguish comment syntax from string content. The JSONC syntax rules and the purpose of Microsoft’s scanner/parser support using a parser rather than a broad regular expression.

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.
Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

For example, a string value may contain a URL-like sequence with //. Removing everything from that marker to the end of the line would change the string rather than remove a comment. Likewise, comment-like characters inside quoted text are data. Let the parser identify comments in context instead of treating every matching character sequence as syntax.

Do not assume every parser accepts trailing commas

Trailing-comma support varies. The reference jsonc-parser default is to disallow them, so explicitly enable the option only when the source dialect requires it. If the input is expected to reject trailing commas, leave the option disabled. This matters when moving a file between editors, scripts, libraries, or receiving applications: one tool’s permissive setting does not establish a universal JSONC rule.

Do not treat comment stripping as validation

Stripping comments can be useful when preserving much of the original text matters, but it does not necessarily produce valid JSON. A trailing comma or another syntax error may remain. Parse, inspect errors, and serialize when you need dependable strict JSON output. If you do use comment stripping for a special formatting-preservation need, follow it with a real validation step rather than assuming the result is ready to consume.

Do not substitute JSON5 without checking the input dialect

JSON5 includes comments and trailing commas but supports other syntax extensions too. A JSON5 parser is appropriate when the file is actually intended to follow JSON5, not merely because it also recognizes comments. Choosing a broader parser can accept syntax that the intended JSONC policy would reject. Check the file’s intended dialect and the parser’s accepted syntax before selecting a tool.

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

Do not expect comments to appear in the output

Comments are ignored while parsing and do not form part of the JSON value representation. A normal parse-and-serialize conversion therefore drops them along with source formatting choices. If the comments explain how humans should edit the configuration, preserve the commented source as a maintained file and generate strict JSON as a separate artifact, or move the explanation into documentation or explicit data fields where appropriate. Do not expect the strict JSON output to retain comment annotations.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Conversion checklist

  • Confirm that the source is intended to be JSONC, rather than JSON5 or another format.
  • Identify whether it contains trailing commas and choose parser settings accordingly.
  • Read the file as text and parse it with a JSONC-aware tool.
  • Check diagnostics and stop on errors before writing a destination file.
  • Serialize the parsed value with a standard JSON serializer.
  • Keep the original JSONC separately if its comments or original formatting are useful to readers.
  • Optionally validate the result with a strict JSON parser or the destination application’s own validation step.

Frequently Asked Questions

What is the safest way to convert JSONC to JSON?

Parse the source with a JSONC-aware parser, inspect its errors, then serialize the parsed value with a standard JSON serializer. Validate the resulting file with a strict JSON parser or the receiving application when needed.

Does converting JSONC to JSON preserve comments?

No. Comments are not part of the JSON value representation, so parsing and serializing preserves data values but drops comments and the source’s original formatting. Keep the JSONC source or store explanations separately if readers still need them.

Do JSONC files always allow trailing commas?

No. The JSONC specification does not require every implementation to accept trailing commas. Microsoft’s reference jsonc-parser disallows them by default, so configure the parser intentionally for the syntax your files use.

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

Can I remove JSONC comments with a regular expression?

A broad regular expression is risky because comment-like sequences such as // and /* can occur inside quoted strings. Prefer a syntax-aware parser or scanner. Comment stripping by itself also does not validate the remaining syntax or handle trailing commas.

Is JSONC the same as JSON5?

No. JSON5 includes comments and trailing commas but supports additional syntax extensions. Use a JSON5 parser only when the input is intended to be JSON5, not simply because the file contains comments.

Which Node.js package can parse JSONC?

Microsoft’s jsonc-parser is a documented option. Its parser exposes an error list that should be checked, and its allowTrailingComma setting should match the input dialect.

How can I convert JSONC in Go?

The tidwall/jsonc package documents a ToJSON conversion function. Consult the package’s current documentation for its API, then validate the converted result with the application’s normal JSON decoder.

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

The Bottom Line

For strict JSON output, use a JSONC-aware parser, check its diagnostics, and serialize the parsed value with a standard JSON serializer. Choose trailing-comma behavior explicitly, keep the JSONC source if its comments matter, and validate the output with the consumer that will use it.

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.