eslint-plugin-json
raw JSON → 4.0.1 verified Sat Apr 25 auth: no javascript
ESLint plugin for linting JSON files. Version 4.0.1 supports ESLint flat config and requires Node >=18. It uses VSCode's JSON parser for linting, replacing JSHint in v1.3.1. Recommended for ensuring valid JSON, catching duplicate keys, trailing commas, and other issues. Supports allowing comments. The plugin ships with recommended configs for both flat and legacy ESLint formats.
Common errors
error Failed to load plugin 'json': Cannot find module 'eslint-plugin-json' ↓
cause Plugin not installed or not in node_modules.
fix
npm install --save-dev eslint-plugin-json
error ESLint: Error while loading rule 'json/undefined': Rule not found ↓
cause Legacy config using individual rules without specifying processor.
fix
Add processor: 'json/json' in flat config or use recommended config.
error ESLint: Expected linebreaks to be 'LF' but found 'CRLF' ↓
cause This rule is from another plugin (e.g., eslint-plugin-linebreak), not this one.
fix
This is not a json plugin issue; configure linebreak-style rule elsewhere.
Warnings
breaking ESLint v9+ requires flat config; plugin v4+ needed. ↓
fix Use eslint-plugin-json v4+ and flat config format (eslint.config.js).
breaking ESLint v9 dropped --ext flag support for some formats; use files in flat config. ↓
fix Define files glob in eslint.config.js instead of --ext .json.
gotcha The rule json/* applies all linting rules; configuring individual rules may override. ↓
fix Use individual rules like 'json/undefined' for granular control, or set severity on json/*.
gotcha Legacy configs (recommended-legacy) are deprecated in favor of flat config. ↓
fix Migrate to flat config and use recommended config.
deprecated Use of .eslintrc config format is deprecated for new projects with ESLint v9+. ↓
fix Switch to eslint.config.js (flat config).
Install
npm install eslint-plugin-json yarn add eslint-plugin-json pnpm add eslint-plugin-json Imports
- default
import json from 'eslint-plugin-json' - json
import json from 'eslint-plugin-json' - configs (recommended)
json.configs['recommended'] - configs (recommended-legacy)
json.configs['recommended-legacy']
Quickstart
// eslint.config.js (flat config)
import json from 'eslint-plugin-json';
export default [
{
files: ['**/*.json'],
...json.configs['recommended']
}
];
// Then run: npx eslint . --ext .json