Skip to content

Commit f140ee7

Browse files
committed
Structure json more nicely
1 parent 72564e2 commit f140ee7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cve_bin_tool/OutputEngine.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,27 @@ def output_cves(self, outfile, output=None):
3030
else: # csv, console, or anything else that is unrecognised
3131
self.output_csv(outfile)
3232

33+
def formatted_modules(self):
34+
""" Returns self.modules converted into form
35+
formatted_output[modulesname][version] = {
36+
"cve": cve_number,
37+
"severity": cve_severity,
38+
}
39+
"""
40+
formatted_output = {}
41+
for modulename in self.modules:
42+
formatted_output[modulename] = {}
43+
for version, cves in self.modules[modulename].items():
44+
formatted_output[modulename][version] = []
45+
for cve_number, cve_severity in cves.items():
46+
formatted_output[modulename][version].append(
47+
{"cve": cve_number, "severity": cve_severity,}
48+
)
49+
return formatted_output
50+
3351
def output_json(self, outfile):
3452
""" Output a JSON of CVEs """
35-
json.dump(self.modules, outfile)
53+
json.dump(self.formatted_modules(), outfile)
3654

3755
def output_csv(self, outfile):
3856
""" Output a CSV of CVEs """

0 commit comments

Comments
 (0)