eslint-plugin-jsonc

raw JSON →
3.1.2 verified Sat Apr 25 auth: no javascript

ESLint plugin for linting JSON, JSONC, and JSON5 files using ESLint rules and custom rules. Current stable version is 3.1.2 with frequent releases (multiple releases per year). The plugin parses JSON files with a custom parser (jsonc-eslint-parser) based on acorn, and provides 50+ rules including auto-fix for style issues. Key differentiators vs alternatives: supports JSONC and JSON5 syntax (comments, trailing commas, etc.), integrates with Vue SFC custom blocks, has more rules than @eslint/json, and supports ESLint directives. Since v3.0.0, the plugin exports a `languages` object for ESLint language plugin integration. Requires Node >=20.19 and ESLint >=9.38.0.

error Error: ESLint configuration in eslint.config.js is invalid: - Unexpected top-level property 'language'.
cause Using `language` in flat config but ESLint version is <9.38.0 or the plugin's language plugins are not loaded correctly.
fix
Upgrade ESLint to >=9.38.0 and ensure the import of eslint-plugin-jsonc is correct: import plugin from 'eslint-plugin-jsonc' and use plugins: { jsonc: plugin }.
error Parsing error: Unexpected token /
cause Attempting to lint a JSONC file (with comments) using the standard `json/json` language which does not allow comments.
fix
Set language: 'json/jsonc' for files with comments.
error Cannot find module 'eslint-plugin-jsonc'
cause Missing the package or using incorrect import path.
fix
Run npm install eslint-plugin-jsonc --save-dev and ensure the import is correct (e.g., import plugin from 'eslint-plugin-jsonc').
gotcha Since v3.0.0, the plugin exports a `languages` object. Configs using `language` must be used instead of the legacy `parser` and `processor` settings.
fix Use `language: 'json/json'` etc. in flat config. See documentation for migration.
breaking v3.0.0 dropped support for ESLint <9.38.0. The plugin now requires ESLint >=9.38.0 and Node >=20.19.
fix Upgrade ESLint to >=9.38.0 and Node to >=20.19.
deprecated The legacy config format (eslintrc) is deprecated. v3.0.0 heavily favors flat config.
fix Migrate to flat config (eslint.config.js). You can use the `configs` export for predefined configs.
gotcha Using the plugin without setting the correct `language` will not lint JSON files correctly. The default language is JavaScript, so JSON-specific rules won't apply.
fix Set `language: 'json/json'` or appropriate language in the flat config object.
breaking v2.x and v3.x have major differences in configuration. The exported `languages` object was added in v3.0.0.
fix If upgrading from v2, use the `languages` export and set `language` in flat config.
gotcha Some rules like `jsonc/no-comments` require a language that supports comments (jsonc or json5). Using it with `json/json` will cause parsing errors.
fix Ensure the language supports comments: use `json/jsonc` or `json/json5` as appropriate.
npm install eslint-plugin-jsonc
yarn add eslint-plugin-jsonc
pnpm add eslint-plugin-jsonc

Configure ESLint flat config for JSON and JSON5 files using eslint-plugin-jsonc.

// eslint.config.js
import plugin from 'eslint-plugin-jsonc';

export default [
  {
    files: ['**/*.json'],
    language: 'json/json',
    plugins: { jsonc: plugin },
    rules: {
      'jsonc/no-comments': 'error',
      'jsonc/sort-keys': 'error',
    },
  },
  {
    files: ['**/*.json5'],
    language: 'json/json5',
    plugins: { jsonc: plugin },
    rules: {
      'jsonc/valid-json-number': 'error',
      'jsonc/auto': 'warn',
    },
  },
];