Click here to Skip to main content
15,888,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
NVD - Data Feeds[^]

I am reading the json nvd feed in the above link and trying to output the ID and the impactScore. I did all these but I don't know how to format the output file, like add each in columns with headers and new rows. Please help me or guide me to a link that will teach me this. I tried online sources but couldn't find any. Thank you!

What I have tried:

Python
#!/usr/bin/python
# -*- coding: utf-8 -*-

import json

with open('nvdcve.json', 'r') as f:
    cve_dict = json.loads(f.read())


i = 0

with open('analyse.json', 'w') as outfile:

    for i in range(0, 5949):
        try:
            nvd_impact = cve_dict['CVE_Items'][i]['impact'
                    ]['baseMetricV2']['impactScore']
            nvd_id = cve_dict['CVE_Items'][i]['cve']['CVE_data_meta']['ID']
            json.dump(nvd_impact, outfile)
            json.dump(nvd_id, outfile)
            print (nvd_id)
        except KeyError:
            continue
Posted
Updated 5-Feb-18 22:19pm
v2

1 solution

 
Share this answer
 
Comments
NewbieAR 6-Feb-18 13:54pm    
I checked it out and still don't understand how to format mine. Is there a better way to put this in a variable in python and then format? (json.dump(nvd_impact, outfile) , json.dump(nvd_id, outfile) )
Richard MacCutchan 6-Feb-18 15:58pm    
I don't know what more you want. The detail in the link above gives you all the information you need, and shows an example. If you find that too difficult then just use the standard Python print statement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900