eslint-plugin-json-format

raw JSON →
2.0.1 verified Fri May 01 auth: no javascript maintenance

An ESLint plugin to lint, format, auto-fix, and sort JSON files. Version 2.0.1 is the latest stable release (last updated September 2019). It extends ESLint's capabilities to handle .json and rc files (like .eslintrc, .babelrc) with auto-fix support. Key differentiators include built-in package.json sorting (standard/pro/custom order), ignoring JSON-with-comments files like tsconfig.json, and ignoring package-lock.json by default. Requires ESLint >= 3.2.1. The plugin is in maintenance mode with no recent updates.

error Cannot read property 'getFilename' of undefined
cause ESLint version mismatch: plugin requires ESLint >= 3.2.1, but used with an older version.
fix
Update ESLint to version >=3.2.1: npm install eslint@latest --save-dev
error Configuration for rule "json-format/json-format" is invalid
cause Trying to configure a rule that does not exist or using incorrect rule name prefix.
fix
Use 'json-format/sort-package-json' or 'json-format/*' wildcard, not 'json-format/json-format'. Example: 'rules': { 'json-format/*': 'error' }
error ESLint couldn't find the plugin "eslint-plugin-json-format"
cause Plugin not installed or not listed in package.json dependencies.
fix
Run 'npm install eslint-plugin-json-format --save-dev' and ensure your ESLint config file is in the project root.
error Unexpected token / in JSON at position 0
cause Plugin tried to parse a JSON file with comments (JSONC) without explicit configuration.
fix
Add the file pattern to 'json/json-with-comments-files' setting or remove comments from the file.
breaking In v2.0.0, the setting 'package-json-sort-order' was renamed to 'sort-package-json'.
fix Use 'json/sort-package-json' instead of 'json/package-json-sort-order'.
breaking The 'sort-package-json' setting now expects a string ('standard', 'pro', false) or an array. Previously it accepted a different format.
fix Update your configuration to match the new schema (e.g., 'json/sort-package-json': 'standard').
gotcha The plugin will strip comments from files listed in 'json-with-comments-files' (like tsconfig.json) if linted with --fix.
fix Do not include files that require comments (e.g., .vscode/settings.json) in 'json-with-comments-files', or disable auto-fix for those files.
gotcha To lint hidden files (e.g., .eslintrc.json), you must explicitly include them using a .eslintignore or the --ext flag with explicit names.
fix Add '!.*' to .eslintignore or use 'eslint --ext .js,.json input/.eslintrc.json'.
deprecated The plugin is no longer actively maintained; last release was in 2019.
fix Consider alternatives like eslint-plugin-json or eslin-plugin-jsonc for newer ESLint versions.
npm install eslint-plugin-json-format
yarn add eslint-plugin-json-format
pnpm add eslint-plugin-json-format

Install ESLint and the plugin, create a minimal .eslintrc.json configuration, and run ESLint with --fix on JSON files to auto-format and sort.

npm install eslint --save-dev
npm install eslint-plugin-json-format --save-dev

echo '{"plugins":["json-format"],"settings":{"json/sort-package-json":"standard","json/ignore-files":["**/package-lock.json"],"json/json-with-comments-files":["**/tsconfig.json",".vscode/**"]}}' > .eslintrc.json

echo '{"name":"test","version":"1.0.0","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"license":"ISC"}' > package.json

eslint --ext .js,.json,.eslintrc,.babelrc --fix .