eslint-plugin-json5

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

An ESLint plugin providing a preprocessor to lint JSON5 files using standard ESLint rules for JavaScript objects. The plugin works by treating JSON5 files as JavaScript object literals, allowing all standard ESLint rules (e.g., no-undef, quotes) to apply. Current stable version is 0.1.4, with no major updates since 2020. It supports ESLint 3-8 via broad peer dependency range. Key differentiator: avoids writing separate JSON5-specific rules by reusing existing ESLint infrastructure. No TypeScript support, no monorepo integration, no file watching improvements. Last released May 2020.

error Error: No configuration for .json5 files found. Make sure you add --ext json5 to your command.
cause ESLint does not automatically lint .json5 files without specifying the extension.
fix
Run 'eslint . --ext json5' or add 'overrides' in eslintrc for '*.json5' files.
error Parsing error: Unexpected token /
cause JSON5 files contain comments, but the plugin expects valid JavaScript object literals (which it gets), but if the file is parsed as JSON by another tool, comments cause errors.
fix
Only use this plugin with ESLint; do not try to parse the file as JSON. Ensure the file is treated as .json5 and not .json.
error Warning: The 'no-undef' rule found undefined variable 'someKey'
cause The processor treats the entire file as a JavaScript object, so keys that are not defined as global or local variables trigger no-undef.
fix
Disable 'no-undef' rule for JSON5 files in overrides, or add dummy globals.
gotcha The plugin only processes JSON5 files; you must specify --ext json5 on the ESLint CLI.
fix Use 'eslint . --ext json5' or configure overrides in eslintrc for json5 files.
gotcha All rules apply as if the JSON5 content is a JavaScript object literal, which can cause unintended errors like 'no-undef' on values.
fix Disable conflicting rules for JSON5 files via overrides or adjust configuration.
lost No version has been released since 2020; there is no active maintenance or bug fixes.
fix Consider alternatives like eslint-plugin-jsonc or directly parse JSON5 with your own scripts.
gotcha The plugin adds a preprocessor that transforms the file's extension to .json, which may interfere with other file-type plugins.
fix Ensure no other processor handles .json files with conflicting transformations.
npm install eslint-plugin-json5
yarn add eslint-plugin-json5
pnpm add eslint-plugin-json5

Shows how to install and configure the plugin, then lint a JSON5 file with standard rules like no-undef and quotes.

// Ensure ESLint is installed locally
// Install the plugin
// npm install --save-dev eslint-plugin-json5

// .eslintrc.json
{
  "plugins": ["json5"],
  "extends": ["eslint:recommended"],
  "rules": {
    "no-undef": "error",
    "quotes": ["error", "double"]
  }
}

// Run ESLint on JSON5 files
// npx eslint . --ext json5

// Example .json5 file (config.json5)
{
  // comment
  port: 8080,
  host: 'localhost',
  unquoted: true
}