Skip to content
← All Tools
๐Ÿ”’All processing in your browser ๐ŸšซNo uploads stored ๐Ÿ›ก๏ธPrivacy-first conversion tools โœ“No login required
Guide

The Complete Guide to Jsonc Validating: Everything You Need to Know

Bill Crawford — Developer Guide — 2026  ยท  Published March 26, 2026

JSONC โ€” JSON with Comments โ€” is a practical extension of JSON that allows developers to annotate configuration files with single-line (//) and multi-line (/* */) comments, as well as trailing commas in objects and arrays. It is the native format of tsconfig.json, VS Code's settings.json, and many modern build tool configuration files. But JSONC introduces ambiguity: a file with a .jsonc extension is not valid JSON, and a file written to be JSONC may still contain structural errors that only appear when the file is parsed by the consuming application.

JSONC validation solves this problem by stripping comments and trailing commas, then feeding the result to a strict JSON parser. This guide explains what JSONC validation is, what the validator checks, how to read its output, and best practices for managing JSONC files in development and production workflows.

Connect on LinkedIn โ†’

Validate your JSONC file instantly: Strips comments and trailing commas, checks structure, depth, encoding, duplicate keys, and more โ€” free, private, no uploads.

Open Jsonc Validator โ†’

Table of Contents

  1. What Is JSONC Validation?
  2. Why Validate JSONC Files?
  3. Comment Stripping
  4. Trailing Commas
  5. JSON Structure Validation
  6. Encoding Issues
  7. Depth Analysis
  8. Duplicate Keys
  9. File Statistics and Preview
  10. Best Practices
  11. Common Use Cases

What Is JSONC Validation?

JSONC validation is the process of parsing a JSONC file โ€” stripping its comments and trailing commas โ€” and confirming that the resulting structure is valid JSON. A JSONC validator goes beyond a simple JSON parser by first applying JSONC-specific preprocessing rules, then validating the cleaned content, and finally reporting additional structural information such as nesting depth, node counts, duplicate keys, and encoding anomalies.

Browser-based JSONC validation reads the file using the Web File API and processes it entirely in JavaScript. Your configuration data โ€” which may contain API endpoints, feature flags, connection strings, or other environment-specific values โ€” never leaves your device. This makes browser-based validation safe to use with real configuration files from production systems.

Why Validate JSONC Files?

JSONC files fail in specific, predictable ways that are easy to overlook during manual editing. Common scenarios where validation catches real problems:

Comment Stripping

JSONC supports two comment syntaxes inherited from JavaScript:

The validator's comment-stripping step must handle several edge cases correctly:

After stripping comments, the validator reports the total number of comment tokens removed. This count appears in the file statistics panel and is useful for confirming the stripping step ran at all โ€” a count of zero on a file you know contains comments indicates a problem.

Trailing Commas

Standard JSON forbids trailing commas โ€” a comma after the last element in an array or the last property in an object. JSONC permits them, making it easier to add, remove, and reorder items without hunting for the comma that needs to be added or removed each time:

{
  "compilerOptions": {
    "target": "ES2022",
    "strict": true,    // trailing comma โ€” valid JSONC, invalid JSON
  }
}

The validator strips trailing commas before passing the content to the JSON parser. Like comment stripping, trailing comma removal must be aware of string boundaries โ€” a string value that ends with a comma followed by a closing brace should not have that comma removed.

If a file has no trailing commas, the validator still processes it correctly โ€” trailing comma removal is a no-op in that case, and the file is valid as both JSONC and standard JSON.

JSON Structure Validation

After preprocessing, the cleaned content is passed to the native browser JSON parser โ€” the same parser used by JSON.parse() in JavaScript. This is the strictest and most accurate JSON validator available in a browser environment, because it is the actual production parser used by the JavaScript engine.

If the cleaned content is not valid JSON, the parser throws an error with a message and position. Common structural errors the validator surfaces:

The validator displays the raw error message from the JSON parser, which includes the character position where the error was detected. This position refers to the cleaned content after comment and trailing comma removal, not the original file โ€” but the validator also reports the original line count to help you locate the error in context.

Encoding Issues

JSON files must be encoded in UTF-8 without a byte order mark (BOM). The BOM is a three-byte sequence (0xEF 0xBB 0xBF) that some text editors โ€” particularly older versions of Microsoft Notepad and certain Windows tools โ€” prepend to UTF-8 files to identify the encoding. Strict JSON parsers treat the BOM as unexpected content and fail immediately.

The validator checks the first bytes of the file for the UTF-8 BOM and reports it as a warning if found. Most JSONC consumers will reject a BOM-prefixed file, so this warning should be resolved by re-saving the file without the BOM.

The validator also checks for null bytes in the file content. Null bytes indicate either binary content mistakenly given a .jsonc extension, or a file that was saved in a wide-character encoding such as UTF-16 or UTF-32 rather than UTF-8. Either situation requires correcting the file before it can be used as a JSONC configuration.

Depth Analysis

The validator measures the maximum nesting depth of the JSON structure โ€” the deepest level of nested objects and arrays. A top-level object containing a key whose value is an array of objects each containing another object would have a depth of 3.

Most JSON parsers handle arbitrary nesting depth, but some environments impose stack depth limits that can cause a parser to crash or throw a range error when parsing deeply nested structures. JavaScript's V8 engine, for example, has a recursion limit that can be exceeded by pathologically nested JSON.

In practice, most configuration files have depths of 3โ€“8. A configuration file with a depth above 15 is unusual and worth reviewing โ€” deep nesting often indicates that the structure could be flattened or reorganized for clarity. The validator flags extremely deep structures (above a configurable threshold) as warnings, not errors, since deep nesting is not technically invalid JSON.

Duplicate Keys

The JSONC and JSON specifications do not prohibit duplicate keys within an object, but the behavior when they appear is implementation-defined. The vast majority of parsers silently use the last value for a duplicated key, discarding all earlier occurrences. A few parsers use the first value. Some parsers throw an error. In all cases, a configuration file with duplicate keys is almost certainly a bug.

Common sources of duplicate keys in real configuration files:

The validator checks for duplicate keys at every nesting level โ€” not just the top level. A duplicate key buried inside a nested object is just as likely to cause a silent bug as one at the top level, but is much harder to spot through manual inspection of a large file.

File Statistics and Preview

For valid JSONC files, the validator reports a set of structural statistics in addition to the pass/fail result:

The structure preview panel renders the top-level keys and their value types (object, array, string, number, boolean, null) in a table. This gives you an immediate visual overview of the file's shape without having to read through the full content โ€” useful for large configuration files where you want to confirm the top-level structure is what you expect before diving into nested sections.

Best Practices

For developers working with JSONC configuration files โ€” whether in TypeScript projects, VS Code workspaces, build tool configs, or custom tooling โ€” these practices reduce the risk of configuration errors reaching production:

Common Use Cases

TypeScript project configuration. The tsconfig.json file is actually a JSONC file โ€” the TypeScript compiler parses it with comment and trailing comma support. Developers frequently add comments to document non-obvious compiler options (strict, moduleResolution, target) and to keep a record of options that were considered and rejected. Validating tsconfig.json files before committing ensures the TypeScript compiler will be able to parse them correctly.

VS Code configuration. VS Code's settings.json, launch.json, tasks.json, and extension configuration files are all JSONC. Teams that store workspace configuration in version control validate these files to catch errors before they prevent colleagues from opening the workspace.

ESLint and Prettier configuration. ESLint supports JSONC configuration files (.eslintrc.jsonc), and Prettier can be configured via a .prettierrc that accepts JSONC syntax. These files are often modified by multiple developers and benefit from validation in CI.

Build tool configuration. Bundlers such as webpack, Rollup, and esbuild can be configured via JSON or JSONC files. Complex build configurations โ€” with multiple entry points, output formats, plugin configurations, and environment-specific overrides โ€” are easier to maintain with comments and trailing commas, making JSONC the natural choice.

API mock and fixture files. Development teams that use static JSON fixture files for API mocking sometimes convert them to JSONC to add inline annotations explaining what each fixture represents, what edge case it tests, and what data it was derived from. Validating these files ensures the annotations haven't introduced syntax errors that would break the mock server.

Configuration management in monorepos. Monorepos with many packages often have root-level JSONC configurations (for TypeScript, ESLint, Prettier, or custom tooling) that govern all packages. A syntax error in a root-level configuration file can break every package in the repository simultaneously. Validation before commit is especially important for these files.

BC
Bill Crawford
Founder, Data Conversion Center

Bill Crawford is a data systems developer and technical founder with over 30 years of professional experience in accounting, finance, and business operations. He founded DataConversionCenter.com to build practical, browser-based tools that simplify complex data challenges.

Professional Background