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.
Print to stdout
(Terminal)¶
If you want to format the output in JSON and print it at stdout, you can replace the JSON filename
with a “-“, like --json-pp -
instead of --json-pp output.json
.
The following command will output the scan results in JSON format to stdout
(In the Terminal):
./scancode -clpieu --jsonlines - samples/
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 results.license_copyright %}
{% for location, data in results.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 sample.json --custom-template sample.html samples
Scanning files...
[####################################] 46
Scanning done.
Now are results are saved in t.json
and we can easily view them with head t.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",
]