Home > OS >  Parse JSON Dictionary with Python3
Parse JSON Dictionary with Python3

Time:12-15

I have a JSON representation that looks like the following:

{
    "results": [
       {
         "vulnerabilities": [
         ],
       }
     ]
}

I tried to output just the vulnerabilities portion, but the following doesnt work:

for key, value in json_object.items():
    print(key, ' : ', value)

This prints out the whole results but not just the vulnerabilities

CodePudding user response:

Assuming multiple dicts in results, each with a vulnerabilities key, you can do:

json_object = {
    "results": [
       {
         "vulnerabilities": [
         ],
       }
     ]
}

print([x['vulnerabilities'] for x in json_object['results']])
  • Related