How to specify Scancode Output Format

A basic overview of formatting Scancode Output is presented here.

More information on Scancode Output Formats.

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.txt:
[
    {% 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.txt --custom-template template.txt samples
Scanning files...
  [####################################]  46
Scanning done.

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

[
  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.