Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import csv
- csv_file = csv.writer(open("csv_output.csv", "wb"))
- csv_file.writerow(["id", "field1", "field2", "field3", "field4"])
- for line in [json.loads(l) for l in open("json_input.json", "r").read().split("\n") if len(l) != 0]:
- csv_file.writerow([line['_id']['$oid'].encode('utf-8'),
- line['field1'].encode('utf-8'),
- line['field2'].encode('utf-8'),
- line['field3'].encode('utf-8'),
- line['field4'].encode('utf-8')])
- del csv_file
Add Comment
Please, Sign In to add comment