Skip to content

Instantly share code, notes, and snippets.

@infinite-Joy
Created February 14, 2017 10:47
Show Gist options
  • Save infinite-Joy/967b0fe69a40f85e02f4d40d6dfe55df to your computer and use it in GitHub Desktop.
Save infinite-Joy/967b0fe69a40f85e02f4d40d6dfe55df to your computer and use it in GitHub Desktop.
a small script that takes in json lines and create a csv file
import csv
import jsonlines
#import pprint
# open the file and put it in a list
with jsonlines.open("github_emails_data.jl") as f:
json_file = [line for line in f]
#print(pprint.pprint(json_file))
# get all the keys and find the uniq keys.
# this is needed to build the header for the csv file
all_keys = [list(data.keys()) for data in json_file]
#print(all_keys)
all_keys_uniq = set(x for l in all_keys for x in l)
#print(all_keys_uniq)
# create the csv file and write the contents
with open("github_emails_data.csv", "w") as csvfile:
fieldnames = all_keys_uniq
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for line in json_file:
writer.writerow(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment