{"id":13403,"library":"jsonc-eslint-parser","title":"JSONC ESLint Parser","description":"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.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/ota-meshi/jsonc-eslint-parser","tags":["javascript","eslint","json","jsonc","json5","parser","typescript"],"install":[{"cmd":"npm install jsonc-eslint-parser","lang":"bash","label":"npm"},{"cmd":"yarn add jsonc-eslint-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsonc-eslint-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for ESLint integration, as this is an ESLint parser.","package":"eslint","optional":false}],"imports":[{"note":"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.","wrong":"const { parseForESLint } = require('jsonc-eslint-parser');","symbol":"parseForESLint","correct":"import { parseForESLint } from 'jsonc-eslint-parser';"},{"note":"A utility function for direct JSON/JSONC/JSON5 parsing outside of ESLint's lifecycle. Follows standard ESM import patterns.","wrong":"const parseJSON = require('jsonc-eslint-parser').parseJSON;","symbol":"parseJSON","correct":"import { parseJSON } from 'jsonc-eslint-parser';"},{"note":"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.","wrong":"import jsoncParser from 'jsonc-eslint-parser';","symbol":"jsoncParser (default import style for flat config)","correct":"import * as jsoncParser from 'jsonc-eslint-parser';"}],"quickstart":{"code":"import * as jsoncParser from \"jsonc-eslint-parser\";\n\nexport default [\n  {\n    files: [\"**/*.json\", \"**/*.json5\", \"**/*.jsonc\"],\n    languageOptions: {\n      parser: jsoncParser,\n      parserOptions: {\n        // Optionally set the specific JSON syntax for stricter parsing.\n        // 'JSON', 'JSONC', or 'JSON5'. If omitted, all syntaxes for static values are accepted.\n        // It's often recommended to let eslint-plugin-jsonc handle syntax strictness.\n        jsonSyntax: 'JSONC'\n      }\n    },\n    // Add rules specific to JSON/JSONC/JSON5 files, typically from eslint-plugin-jsonc\n    // plugins: { jsonc: someJsoncPlugin },\n    // rules: {\n    //   'jsonc/key-spacing': 'error'\n    // }\n  },\n];","lang":"typescript","description":"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."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Incorrect 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `parser: 'jsonc-eslint-parser'` to `parser: jsoncParser` after importing it as `import * as jsoncParser from 'jsonc-eslint-parser';`.","cause":"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.","error":"ESLint: Parsing error: 'parser' must be a string or a module object."},{"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).","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'body')"},{"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`.","cause":"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.","error":"SyntaxError: Unexpected token ':' (or similar for other JSON syntax errors)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}