I'm trying to convert a JSON file over to a CSV file but when I run the build it only returns 2 lines the headers and the first entry.
Not sure whats happening i've tried a few different variations but nothing seems to work, not sure if it's because the file is to big or not 6+ million lines...
import json
import csv
with open('result.json') as jsonfile:
data=jsonfile.read()
#ParseFile
jsonobj = json.loads(data)
keylist = []
for key in jsonobj[0]:
keylist.append(key)
f = csv.writer(open("test-kyle.csv", "w"))
f.writerow(keylist)
for record in jsonobj:
currentrecord = []
for key in keylist:
currentrecord.append(record[key])
f.writerow(currentrecord)
Here is the example JSON file:
[
{
"text": "<@U48TMD5QS> has joined the channel",
"ts": "1491388552.433852"
},
{
"text": "*Channel: failed_signup* \nPhone number 123218736 failed to sign up on UGANDA",
"ts": "1491477391.593892"
},
{
"text": "*Channel: failed_signup* \nPhone number 723880908 failed to sign up on UGANDA",
"ts": "1491477392.594092"
},
{
"text": "*Channel: failed_signup* \nPhone number 723880908 failed to sign up on UGANDA",
"ts": "1491477393.594269"
},
{
"text": "*Channel: failed_signup* \nPhone number 723880666 failed to sign up on UGANDA",
"ts": "1491477393.594395"
},
{
"text": "*Channel: IT_ALERTS_GMAIL* \n[kve-t460] Failed to complete import cycle",
"ts": "1491477394.594630"
},
{
"text": "*Channel: failed_signup* \nPhone number abcdefg failed to sign up on UGANDA",
"ts": "1491477434.604899"
},
{
"text": "<@U1Y9UJD8V> has joined the channel",
"ts": "1493358499.130025"
}
]