1

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

1

1 Answer 1

1

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

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

for result in json_object['results']:
    for vuln in result['vulnerabilities']:
        print(vuln)
Sign up to request clarification or add additional context in comments.

3 Comments

Your code splits out this i.imgur.com/x45GwtP.png
anyway to loop over each result within vulnerabilities?
HAve updated answer to iterate over vulnerabilities too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.