JSON Processing Using Python -


i'm trying download json file, save file, , iterate through json file in order extract information , save variables. i'm going format message in csv format send data system. problem json data. appears dictionary within list , i'm not sure how process it.

here's json:

[ {   "ipaddress" : "",   "feeddescription" : "botted node feed",   "bnfeedversion" : "1.1.4",   "generatedts" : "2013-08-01 12:00:10.360+0000",   "count" : 642903,   "firstdiscoveredts" : "2013-07-21 19:07:20.627+0000",   "lastdiscoveredts" : "2013-08-01 00:34:41.052+0000",   "threattype" : "bn",   "confidence" : 82,   "discoverymethod" : "spamtrap",   "indicator" : true,   "supportingdata" : {     "behavior" : "spamming",     "botnetname" : null,     "spamtrapdata" : {       "uniquesubjectcount" : 88     },     "p2pdata" : {       "connect" : null,       "port" : null     }   } }, {   "ipaddress" : "",   "feeddescription" : "botted node feed",   "bnfeedversion" : "1.1.4",   "generatedts" : "2013-08-01 12:00:10.360+0000",   "count" : 28,   "firstdiscoveredts" : "2013-07-19 03:19:08.622+0000",   "lastdiscoveredts" : "2013-08-01 01:44:04.009+0000",   "threattype" : "bn",   "confidence" : 40,   "discoverymethod" : "spamtrap",   "indicator" : true,   "supportingdata" : {     "behavior" : "spamming",     "botnetname" : null,      "spamtrapdata" : {       "uniquesubjectcount" : 9     },     "p2pdata" : {       "connect" : null,       "port" : null     }   } }, {   "ipaddress" : "",   "feeddescription" : "botted node feed",   "bnfeedversion" : "1.1.4",   "generatedts" : "2013-08-01 12:00:10.360+0000",   "count" : 160949,   "firstdiscoveredts" : "2013-07-16 18:52:33.881+0000",   "lastdiscoveredts" : "2013-08-01 03:14:59.452+0000",   "threattype" : "bn",   "confidence" : 82,    "discoverymethod" : "spamtrap",   "indicator" : true,   "supportingdata" : {     "behavior" : "spamming",     "botnetname" : null,     "spamtrapdata" : {       "uniquesubjectcount" : 3     },      "p2pdata" : {       "connect" : null,        "port" : null     }   }  } ] 

my code:

download = 'https:url.bnfeed20130801.json'  request = requests.get(download, verify=false) out  = open(filename, 'w') row in request:     if row.strip():          column in row:                  out.write(column)     else:         continue out.close() time.sleep(4) jsonrequest = request.json()  item in jsonrequest:      print jsonrequest[0]['ipaddress']      print jsonrequest[item]['ipaddress'] --i tried 

when above prints same ip on , on again. i've put in print statement testing purposes only. once figure out to access different elements of json store in variables , use these variables accordingly. appreciated.

thanks in advance help. i'm using python 2.6 on linux.

you iterating on list of dicts, try item['ipaddress'].


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -