Registry / devops / eslint-formatter-json

eslint-formatter-json

JSON →
library9.0.1jsnpmunverified

Official JSON formatter for ESLint, extracted as a standalone package at version 9.0.1. Released alongside ESLint 9.x, matching its output format. Provides typed JSON output of lint results as an array of file result objects. Published independently to avoid depending on the full ESLint package. Supports Node >=18.18.0. Ships TypeScript definitions.

npm install eslint-formatter-json
INSTALL
IMPORT
SIG · ESLINT-FORMATTER-J
E
eslint-formatter-json
devopsjavascriptv9.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import formatter from 'eslint-formatter-json'
const formatter = require('eslint-formatter-json')
Module is ESM-only; CommonJS require will fail.
LintResult
import type { LintResult } from 'eslint-formatter-json'
import { LintResult } from 'eslint-formatter-json'
Use 'import type' to avoid runtime import of type-only exports.
formatter
import formatter from 'eslint-formatter-json'
import { formatter } from 'eslint-formatter-json'
Default export is the formatter function; named export does not exist.

Formats ESLint LintResult array into a JSON string.

import formatter from 'eslint-formatter-json'; const results = [ { filePath: 'foo.js', messages: [{ message: 'Unexpected foo.', severity: 2, line: 5, column: 10, ruleId: 'foo' }], errorCount: 1, warningCount: 0, fixableErrorCount: 0, fixableWarningCount: 0 } ]; const output = formatter(results); console.log(output); // [{"filePath":"foo.js","messages":[{"message":"Unexpected foo.","severity":2,"line":5,"column":10,"ruleId":"foo"}],"errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}]
Debug
Known issues
deprecatedESLint's built-in json formatter is deprecated in ESLint 9.x; use standalone package instead
fix
Switch to eslint-formatter-json standalone package.
affects: >=9.0.0
breakingPackage is ESM-only. CommonJS require() will cause a MODULE_NOT_FOUND error.
fix
Use dynamic import() or set type: "module" in package.json.
affects: >=9.0.0
gotchaOutput format changed in ESLint 9.x: filePath is no longer relative by default. Use options if needed.
fix
Pass results with absolute or relative paths as needed.
affects: 9.x
deprecatedPackage name eslint-formatter-json is for ESLint 9; older versions use eslint's built-in formatter
fix
Use ESLint's built-in format('json') or eslint-formatter-json@8.
affects: <9.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/eslint-formatter-json/index.js
Package is ESM-only but loaded via require()
fix
Use import or dynamic import() instead of require().
Must use import to load ES Module: eslint-formatter-json
ESM package loaded in a CommonJS context
fix
Convert your project to ESM (type: "module" in package.json) or use dynamic import().
Upgrade
Version history
9.0.1latest on npm
Audit
Dependencies
eslintoptionalPeer dependency required to use the formatter with ESLint
Agent activity
6 hits · last 30 days
node
6
Resources
eslint-formatter-json — npm install eslint-formatter-json · libregistry