I have put together a script to output all fields from a json file.
I have running into issues getting it to print each finding from highsev and specifically the id field from each finding.
Here is the code:
json_object=json.load(f)
vulnsBySeverity["HIGHSEVERITY"] = []
for result in json_object['results']:
vulnsBySeverity["HIGHSEVERITY"] = [vuln for vuln in result['vulnerabilities'] if vuln["severity"] == "high"]
highsev=vulnsBySeverity["HIGHSEVERITY"]
print("HIGH VULNS were")
for finding in highsev:
print(highsev[finding]['id'])
Its complaining :
TypeError: list indices must be integers or slices, not dict
I think I understand what its saying that finding call in the print() has to be a int or slice im just wondering how i can do that, as finding contains this:
{'id': 'CVE-2020-15999'}
Im simply just trying to loop through highsev and output the value of id in a loop.
What might i be doing wrong here? can someone please help
>Solution :
You’re already looping through highsev with your for finding in highsev:
If your highsev list contains dictionaries like this {'id': 'CVE-2020-15999'}, you can do this:
for finding in highsev:
print(finding['id'])