Registry / testing / jsonc-eslint-parser

jsonc-eslint-parser

JSON →
library3.1.0jsnpmunverified

jsonc-eslint-parser is a dedicated parser for ESLint that enables linting of JSON, JSONC (JSON with comments), and JSON5 files. Its current stable version is v3.1.0, and it maintains an active release cadence with regular minor and patch updates following major version bumps. This parser differentiates itself by providing a robust Abstract Syntax Tree (AST) specifically tailored for ESLint's linting capabilities, making it an essential component for projects requiring strict code style and error checking within various JSON formats. It is frequently used in conjunction with `eslint-plugin-jsonc` to provide comprehensive rule sets. The library ships with TypeScript types, facilitating its use in TypeScript-based configurations and projects.

npm install jsonc-eslint-parser
INSTALL
IMPORT
SIG · JSONC-ESLINT-PARSE
J
jsonc-eslint-parser
testingjavascriptv3.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseForESLint
import { parseForESLint } from 'jsonc-eslint-parser';
const { parseForESLint } = require('jsonc-eslint-parser');
Primarily used internally by ESLint. For programmatic use in a CommonJS context, you might need dynamic import or a bundler. ESLint's flat config expects ESM import.
parseJSON
import { parseJSON } from 'jsonc-eslint-parser';
const parseJSON = require('jsonc-eslint-parser').parseJSON;
A utility function for direct JSON/JSONC/JSON5 parsing outside of ESLint's lifecycle. Follows standard ESM import patterns.
jsoncParser (default import style for flat config)
import * as jsoncParser from 'jsonc-eslint-parser';
import jsoncParser from 'jsonc-eslint-parser';
When configuring ESLint's flat config, the parser module itself is often imported as a namespace object and directly assigned, rather than a default export.

Demonstrates how to configure jsonc-eslint-parser in an ESLint flat configuration file (`eslint.config.js` or `eslint.config.mjs`) to parse JSON, JSONC, and JSON5 files.

import * as jsoncParser from "jsonc-eslint-parser"; export default [ { files: ["**/*.json", "**/*.json5", "**/*.jsonc"], languageOptions: { parser: jsoncParser, parserOptions: { // Optionally set the specific JSON syntax for stricter parsing. // 'JSON', 'JSONC', or 'JSON5'. If omitted, all syntaxes for static values are accepted. // It's often recommended to let eslint-plugin-jsonc handle syntax strictness. jsonSyntax: 'JSONC' } }, // Add rules specific to JSON/JSONC/JSON5 files, typically from eslint-plugin-jsonc // plugins: { jsonc: someJsoncPlugin }, // rules: { // 'jsonc/key-spacing': 'error' // } }, ];
Debug
Known issues
breakingVersion 3.0.0 dropped support for Node.js versions older than 20.19.0. Users on older Node.js runtimes will encounter errors or require downgrading the parser.
fix
Upgrade your Node.js environment to a supported version (>=20.19.0 || >=22.13.0 || >=24). If unable to upgrade, stick to jsonc-eslint-parser v2.x.
affects: >=3.0.0
gotchaThe `parserOptions.jsonSyntax` option ('JSON', 'JSONC', 'JSON5') enforces strictness at the parsing level. It's often more flexible and recommended to omit this option and instead use rules from `eslint-plugin-jsonc` to report and fix syntax violations, as this allows for more granular control and auto-fix capabilities.
fix
Remove or loosen `parserOptions.jsonSyntax` from your ESLint config. Instead, install and configure `eslint-plugin-jsonc` and apply its specific rules (e.g., `jsonc/no-comments` for strict JSON) to manage syntax strictness.
affects: >=1.0.0
gotchaIncorrect configuration of file extensions in the ESLint config can lead to the parser not being applied, resulting in 'Parsing error: unexpected token' or similar messages if another parser (like default Espree) attempts to process JSON syntax.
fix
Ensure the `files` array in your ESLint configuration (e.g., `files: ['**/*.json', '**/*.json5', '**/*.jsonc']`) correctly targets all JSON-like files you intend this parser to handle.
affects: >=1.0.0
Errors
Common errors & fixes
ESLint: Parsing error: 'parser' must be a string or a module object.
In ESLint's flat configuration, the parser must be an imported module object, not a string path. This error occurs if you try to use the string name of the package instead of importing it.
fix
Change `parser: 'jsonc-eslint-parser'` to `parser: jsoncParser` after importing it as `import * as jsoncParser from 'jsonc-eslint-parser';`.
TypeError: Cannot read properties of undefined (reading 'body')
This often indicates an issue where ESLint is attempting to lint a JSON file, but the `jsonc-eslint-parser` isn't correctly applied, leading to a default JavaScript parser trying to parse JSON as JavaScript.
fix
Verify that your `files` array in the ESLint configuration correctly targets your JSON files and that the `languageOptions.parser` is set to `jsoncParser` for those files. Also check for Node.js version compatibility (v3.0.0+ requires Node.js >=20.19.0).
SyntaxError: Unexpected token ':' (or similar for other JSON syntax errors)
This can happen if the `jsonSyntax` option in `parserOptions` is set too strictly for the file being parsed (e.g., `jsonSyntax: 'JSON'` for a JSONC file with comments) or if the parser itself is outdated for the given syntax.
fix
Either loosen or remove the `parserOptions.jsonSyntax` option, or ensure it matches the specific flavor of JSON/JSONC/JSON5 you are parsing. Also, ensure you are on the latest compatible version of `jsonc-eslint-parser`.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
eslintrequiredPeer dependency for ESLint integration, as this is an ESLint parser.
Agent activity
2 hits · last 30 days
node
2
Resources
jsonc-eslint-parser — npm install jsonc-eslint-parser · libregistry