Skip to content
Latchkey

ruff --output-format=json: Machine-Readable Output

ruff --output-format=json prints violations as a JSON array, suitable for scripts, dashboards, and report uploaders.

When another tool needs to consume lint results, JSON beats parsing text. Ruff emits a structured record per violation.

What it does

With --output-format=json, ruff check prints a JSON array where each element describes a violation: the rule code, message, filename, and location (start and end row/column), plus fix data when available. The exit code still reflects whether violations remain.

Common usage

Terminal
ruff check --output-format=json .
# count violations by rule with jq
ruff check --output-format=json . | jq 'group_by(.code) | map({code: .[0].code, n: length})'
# save a report artifact
ruff check --output-format=json . > ruff-report.json

Output formats

ValueWhat it does
jsonJSON array of violation objects
json-linesOne JSON object per line
sarifSARIF for code-scanning uploads
github / gitlabCI-platform annotation formats
junitJUnit XML for test reporters

In CI

Write JSON to a file and upload it as a build artifact, or feed it to a dashboard. For GitHub code scanning, prefer --output-format=sarif and the upload-sarif action so findings land in the Security tab.

Common errors in CI

A non-zero exit with valid JSON on stdout is normal: the JSON is the report, the exit code is the gate, so capture stdout before the step fails (it still writes the array). Piping JSON into a parser that also sees a summary line fails; json mode prints only the array. An empty array [] with exit 0 means no violations.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →