How to specify Scancode Output Format

A basic overview of formatting Scancode Output is presented here.

More information on Scancode Output Formats.

Note

Please note that different for different install methods, scan commands vary.

The basic command to perform a scan, in case of a download and configure installation (on Linux/MacOS) is:

path/to/scancode [OPTIONS] <OUTPUT FORMAT OPTION(s)> <SCAN INPUT>

The basic usage, if Scancode is installed from pip, or in Windows:

scancode [OPTIONS] <OUTPUT FORMAT OPTION(s)> <SCAN INPUT>

For more information on how the Scan Command varies for Various Installation Methods/Operating Systems, refer Command Invocation Variations.

JSON

If you want JSON output of ScanCode results, you can pass the --json argument to ScanCode. The following commands will output scan results in a formatted json file:

  • scancode --json /path/to/output.json /path/to/target/dir

  • scancode --json-pp /path/to/output.json /path/to/target/dir

  • scancode --json-lines /path/to/output.json /path/to/target/dir

To compare the JSON output in different formats refer Comparing Different json Output Formats.

HTML

If you want HTML output of ScanCode results, you can pass the --html argument to ScanCode. The following commands will output scan results in a formatted HTML page or simple web application:

  • scancode --html /path/to/output.html /path/to/target/dir

  • scancode --html-app /path/to/output.html /path/to/target/dir

For more details on the HTML output format refer --html FILE.

Warning

The --html-app option has been deprecated, use Scancode Workbench instead.

Custom Output Format

While the three built-in output formats are convenient for a verity of use-cases, one may wish to create their own output template, using the following arguments:

``--custom-output FILE --custom-template TEMP_FILE``

ScanCode makes this very easy, as it uses the popular Jinja2 template engine. Simply pass the path to the custom template to the --custom-template argument, or drop it in a folder to src/scancode/templates directory.

For example, if I wanted a simple CLI output I would create a template2.html with the particular data I wish to see. In this case, I am only interested in the license and copyright data for this particular scan.

## template.html:
[
    {% if files.license_copyright %}
        {% for location, data in files.license_copyright.items() %}
            {% for row in data %}
  location:"{{ location }}",
  {% if row.what == 'copyright' %}copyright:"{{ row.value|escape }}",{% endif %}
             {% endfor %}
         {% endfor %}
    {% endif %}
]

.. note::

    File name and extension does not matter for the template file.

Now I can run ScanCode using my newly created template:

$ scancode -clpeui --custom-output output.json --custom-template template.html samples
Scanning files...
  [####################################]  46
Scanning done.

Now are results are saved in output.json and we can easily view them with head output.json:

[
  location:"samples/JGroups/LICENSE",
  copyright:"Copyright (c) 1991, 1999 Free Software Foundation, Inc.",

  location:"samples/JGroups/LICENSE",
  copyright:"copyrighted by the Free Software Foundation",
]

For a more elaborate template, refer this default template given with Scancode, to generate HTML output with the --html output format option.

Documentation on Jinja templates.