samedi 25 juin 2016

convert csv to json file using python script

import csv import json csvfile = open('test.csv', 'r') jsonfile = open('file.json', 'w') fieldnames = ("bssid","firsttimeseen","lasttimeseen","channel","speed","privacy","cipher","authentication","power","# beacons","# IV","LAN IP", "ID-length","essid") reader = csv.DictReader( csvfile, fieldnames) for row in reader: json.dump(row, jsonfile) jsonfile.write('n') Actually I am not getting expected output like all first row are field names from second row it should consider as elements. please help me. Please respond me soon. test.csv contain "BSSID, First time seen, Last time seen, channel, Speed, Privacy, Cipher, Authentication, Power, # beacons, # IV, LAN IP, ID-length, ESSID, Key" "20:20:22:24:20:20, 2016-05-11 04:11:12, 2016-05-11 04:11:19, 1, 54, WPA2 WPA, CCMP TKIP,PSK, -97, 5, 0, 0. 0. 0. 0, 11, TCSTB242020," "50:57:A8:66:D9:AC, 2016-05-11 04:11:14, 2016-05-11 04:11:19, 6, 54, WPA2, CCMP,PSK, -73, 7, 0, 0. 0. 0. 0, 7, ciscosb," "EC:88:8F:AA:AA:CE, 2016-05-11 04:11:12, 2016-05-11 04:11:19, 1, 54, WPA, CCMP TKIP,PSK, -73, 10, 0, 0. 0. 0. 0, 11, TP-LINK_TCH," "74:26:AC:89:F5:52, 2016-05-11 04:11:15, 2016-05-11 04:11:15, 11, 54, OPN, , , -71, 1, 0, 0. 0. 0. 0, 13, GuestInternet," "74:26:AC:89:F5:51, 2016-05-11 04:11:14, 2016-05-11 04:11:15, 11, 54, WPA2, CCMP, MGT, -67, 2, 0, 0. 0. 0. 0, 1, x00," "74:26:AC:89:F5:50, 2016-05-11 04:11:15, 2016-05-11 04:11:15, 11, -1, WPA, , , -64, 0, 6, 0. 0. 0. 0, 0, ," "78:54:2E:F3:75:6E, 2016-05-11 04:11:12, 2016-05-11 04:11:19, 2, 54, WPA2, CCMP TKIP,PSK, -61, 21, 61, 0. 0. 0. 0, 8, MEG WiFi," "48:EE:0C:CF:BD:F9, 2016-05-11 04:11:12, 2016-05-11 04:11:19, 1, 54, OPN, , , -55, 15, 0, 0. 0. 0. 0, 14, D-Link_DIR-816," "58:6D:8F:7D:E8:30, 2016-05-11 04:11:12, 2016-05-11 04:11:19, 6, 54, WPA2 WPA, CCMP TKIP,PSK, -55, 13, 21, 0. 0. 0. 0, 10, Cisco07652," "04:02:1F:CD:C5:8C, 2016-05-11 04:11:12, 2016-05-11 04:11:20, 13, 54, WPA2, CCMP,PSK, -56, 14, 0, 0. 0. 0. 0, 17, Airtel-E5573-C58C," "F4:EC:38:A6:54:04, 2016-05-11 04:11:12, 2016-05-11 04:11:19, 5, 54, WPA2 WPA, CCMP,PSK, -57, 27, 0, 0. 0. 0. 0, 9, TP-Bucket," "30:91:8F:6B:76:E7, 2016-05-11 04:11:18, 2016-05-11 04:11:18, 11, 54, WPA2 WPA, CCMP TKIP,PSK, -97, 1, 0, 0. 0. 0. 0, 14, No-match2.4ghz,"

Aucun commentaire:

Enregistrer un commentaire