Guest User

Untitled

a guest
Jun 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. import json
  2. import csv
  3.  
  4. csv_file = csv.writer(open("csv_output.csv", "wb"))
  5. csv_file.writerow(["id", "field1", "field2", "field3", "field4"])
  6. for line in [json.loads(l) for l in open("json_input.json", "r").read().split("\n") if len(l) != 0]:
  7. csv_file.writerow([line['_id']['$oid'].encode('utf-8'),
  8. line['field1'].encode('utf-8'),
  9. line['field2'].encode('utf-8'),
  10. line['field3'].encode('utf-8'),
  11. line['field4'].encode('utf-8')])
  12. del csv_file
Add Comment
Please, Sign In to add comment