Skip to content

Commit 9c0774c

Browse files
committed
#425: JSON outputs no longer pretty-printed by default; added format option 'json-pp' for pretty-printed JSON outputs.
1 parent 088e86a commit 9c0774c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/scancode/cli.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class ScanCommand(utils.BaseCommand):
245245
Try 'scancode --help' for help on options and arguments.'''
246246

247247

248-
formats = ('json', 'html', 'html-app', 'spdx-tv', 'spdx-rdf')
248+
formats = ('json', 'json-pp', 'html', 'html-app', 'spdx-tv', 'spdx-rdf')
249249

250250
def validate_formats(ctx, param, value):
251251
value_lower = value.lower()
@@ -655,7 +655,7 @@ def save_results(files_count, scanned_files, format, input, output_file):
655655
except HtmlAppAssetCopyError:
656656
echo_stderr('\nFailed to create HTML app.', fg='red')
657657

658-
elif format == 'json':
658+
elif format == 'json' or format == 'json-pp':
659659
import simplejson as json
660660

661661
meta = OrderedDict()
@@ -664,7 +664,10 @@ def save_results(files_count, scanned_files, format, input, output_file):
664664
meta['files_count'] = files_count
665665
# TODO: add scanning options to meta
666666
meta['files'] = scanned_files
667-
output_file.write(unicode(json.dumps(meta, indent=2 * ' ', iterable_as_array=True, encoding='utf-8')))
667+
if format == 'json-pp':
668+
output_file.write(unicode(json.dumps(meta, indent=2 * ' ', iterable_as_array=True, encoding='utf-8')))
669+
else:
670+
output_file.write(unicode(json.dumps(meta, iterable_as_array=True, encoding='utf-8')))
668671
output_file.write('\n')
669672

670673
elif format == 'spdx-tv' or format == 'spdx-rdf':

0 commit comments

Comments
 (0)