flake8-json

raw JSON →
24.4.0 verified Mon Apr 27 auth: no python

Flake8 plugin that formats linting results as JSON. Currently at version 24.4.0, compatible with Python >=3.6. Part of the PyCQA ecosystem. Updates follow Flake8 releases.

pip install flake8-json
error ModuleNotFoundError: No module named 'flake8_json'
cause The package 'flake8-json' is not installed or imported incorrectly (hyphen vs underscore).
fix
Install with 'pip install flake8-json' and import as 'import flake8_json' (underscore).
error Flake8 reported no JSON output
cause The --format flag was not set to 'json' or the plugin is not registered.
fix
Run flake8 with --format json. Verify plugin is installed: 'pip list | grep flake8-json'.
error Error: 'format' is not a recognized option
cause Flake8 version is too old to support the --format flag.
fix
Upgrade flake8 to >=3.0.0. flake8-json requires flake8 >=3.0.0.
gotcha flake8-json is a formatting reporter; it does not add new lint checks. To get JSON output, use the --format json flag when invoking flake8.
fix Run flake8 with --format json (or configure in setup.cfg).
breaking Versions prior to 24.4.0 may have different behavior for nested violations. Always check the output schema if upgrading from an older version.
fix Upgrade to 24.4.0 and adjust parsing if needed.
deprecated Using 'flake8-json' as a package name (hyphen) is deprecated; import using underscore: 'flake8_json'.
fix Use 'from flake8_json import ...' instead of 'from flake8-json import ...'.

Run flake8 with JSON output format on a file.

import subprocess
result = subprocess.run(['flake8', '--format', 'json', 'myfile.py'], capture_output=True, text=True)
print(result.stdout)