{"id":9222,"library":"pylint-json2html","title":"Pylint JSON to HTML Converter","description":"pylint-json2html is a Python utility that transforms Pylint's JSON report output into a human-readable HTML document. This library addresses the removal of native HTML output from Pylint since version 1.7. It provides a simple command-line interface to generate presentable code quality reports. The current version is 0.5.0, with releases occurring as needed rather than on a fixed cadence.","status":"active","version":"0.5.0","language":"en","source_language":"en","source_url":"https://github.com/Exirel/pylint-json2html","tags":["pylint","linter","html","json","report","code quality","static analysis"],"install":[{"cmd":"pip install pylint-json2html","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required to generate the initial JSON report.","package":"pylint","optional":false},{"reason":"Used for templating the HTML output. Implicitly installed with pylint-json2html.","package":"Jinja2","optional":false}],"imports":[],"quickstart":{"code":"import subprocess\nimport os\n\n# Create a dummy Python file to lint\nwith open('my_module.py', 'w') as f:\n    f.write('def my_func():\\n    \"\"\"Missing docstring for function.\"\"\"\\n    pass\\n')\n\n# 1. Run Pylint to generate a JSON report\n# We use a temporary file for Pylint's output, then read it.\n# In a real scenario, you'd pipe directly: `pylint my_module.py --output-format=json | pylint-json2html -o report.html`\ntry:\n    pylint_cmd = ['pylint', 'my_module.py', '--output-format=json', '--msg-template=\"{path}:{line}:{column}: {msg_id}: {msg} ({symbol})\"']\n    pylint_process = subprocess.run(pylint_cmd, capture_output=True, text=True, check=True)\n    pylint_json_output = pylint_process.stdout\n    \n    # Save Pylint's JSON output to a temporary file for demonstration\n    with open('pylint_report.json', 'w') as f:\n        f.write(pylint_json_output)\n\n    # 2. Convert the JSON report to HTML using pylint-json2html\n    # Note: pylint-json2html is typically used via piping, but for programmatic demo, \n    # we simulate input from a file or directly pass content if possible (which it is via stdin for the CLI tool).\n    # For this example, we'll run it as a separate command reading the file.\n    html_cmd = ['pylint-json2html', 'pylint_report.json', '-o', 'pylint_report.html']\n    subprocess.run(html_cmd, check=True)\n\n    print(\"HTML report generated at pylint_report.html\")\n    print(\"JSON report saved at pylint_report.json\")\n\nexcept subprocess.CalledProcessError as e:\n    print(f\"An error occurred during pylint or pylint-json2html execution: {e.stderr}\")\nexcept FileNotFoundError:\n    print(\"Error: Pylint or pylint-json2html command not found. Ensure they are installed and in your PATH.\")\nfinally:\n    # Clean up dummy files\n    if os.path.exists('my_module.py'):\n        os.remove('my_module.py')\n    if os.path.exists('pylint_report.json'):\n        os.remove('pylint_report.json')\n    # The generated HTML report is left for inspection\n    # if os.path.exists('pylint_report.html'):\n    #     os.remove('pylint_report.html') # Uncomment to remove HTML as well","lang":"python","description":"This quickstart demonstrates the typical workflow: first, run Pylint on your code, ensuring its output format is set to JSON. Then, pipe this JSON output to `pylint-json2html`, redirecting its HTML output to a specified file. Alternatively, Pylint's output can be saved to a file and passed as an argument to `pylint-json2html`."},"warnings":[{"fix":"Install `pylint-json2html` and pipe Pylint's JSON output to it, or use a similar third-party tool.","message":"Pylint removed its native HTML output format starting from version 1.7. `pylint-json2html` was created to provide this functionality externally. Users upgrading Pylint from versions older than 1.7 will need this or a similar tool to continue generating HTML reports.","severity":"breaking","affected_versions":"Pylint >= 1.7"},{"fix":"Ensure Pylint is run with `--output-format=json` or `--output-format=jsonextended` (for more data) when generating input for `pylint-json2html`. For example: `pylint your_module.py --output-format=json | pylint-json2html -o report.html`.","message":"The `pylint-json2html` tool requires Pylint's output to be in JSON format. Forgetting to specify `--output-format=json` (or `output-format=json` in `.pylintrc`) will result in `pylint-json2html` failing to process the input or generating an empty/malformed HTML report.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly set the output encoding using the `-e utf-8` flag for `pylint-json2html` and ensure your terminal/environment handles UTF-8 correctly. Also, consider setting Python's `PYTHONIOENCODING=utf-8` environment variable if piping issues persist.","message":"When piping Pylint's output, especially in environments with non-UTF-8 default encodings (e.g., `cp1252` or `latin1`), character encoding issues can lead to garbled text in the final HTML report.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you need score or metrics in your HTML report, configure Pylint to output `jsonextended` (e.g., via a custom plugin or Pylint's `--output-format` if it supports it in newer versions, or use the tool's plugin capabilities if applicable) and then run `pylint-json2html -f jsonextended ...`.","message":"There are two main JSON input formats: `json` and `jsonextended`. The default `json` format contains only messages, while `jsonextended` includes additional metrics like score, number of analyzed statements, and dependencies. Using `jsonextended` requires Pylint to output this specific format and `pylint-json2html` to be informed via the `-f jsonextended` flag.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Pylint no longer supports direct HTML output. Instead, generate JSON output (`--output-format=json`) and pipe it to `pylint-json2html`. Example: `pylint my_module.py --output-format=json | pylint-json2html -o report.html`.","cause":"Attempting to use `--output-format=html` directly with Pylint versions 1.7 or newer.","error":"Error: no such option: --output-format=html"},{"fix":"Verify that Pylint is configured to output JSON (`--output-format=json`) and that its output is successfully piped to `pylint-json2html` (e.g., check for errors in the Pylint command itself). Make sure to pass the output file with `-o <filename>.html`.","cause":"Pylint's output was not correctly formatted as JSON, or `pylint-json2html` did not receive any input.","error":"Blank or incomplete HTML report file generated."},{"fix":"Run `pylint-json2html` with the output encoding flag: `pylint ... | pylint-json2html -o report.html -e utf-8`. Also, ensure your terminal supports UTF-8, and consider setting `PYTHONIOENCODING=utf-8`.","cause":"Piping Pylint's output to `pylint-json2html` in a terminal/environment with a non-UTF-8 default encoding, leading to character encoding mismatches.","error":"UnicodeEncodeError: 'charmap' codec can't encode character..."},{"fix":"Ensure you either pipe Pylint's JSON output directly to `pylint-json2html` or provide a JSON filename as a positional argument. Correct usage: `pylint my_file.py --output-format=json | pylint-json2html -o report.html` OR `pylint my_file.py --output-format=json > report.json; pylint-json2html report.json -o report.html`.","cause":"`pylint-json2html` expects a filename as input or data from stdin, but received neither.","error":"pylint-json2html: error: the following arguments are required: FILENAME"}]}