Guest User

jsonParsing

a guest
Feb 13th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import json, csv
  2.  
  3. output = open('test.csv', 'w+')
  4. csv_file = csv.writer(output)
  5.  
  6.  
  7. with open('deplike.json', 'r') as json_file:  
  8.     data = json.load(json_file)
  9. """    for p in data:
  10.        csv_file.writerow([unicode(p).encode('ascii')])
  11.    for x in data.itervalues():
  12.        csv_file.writerow([unicode(x).encode('ascii')])"""
  13.  
  14. all_keys = ['key']
  15. all_keys.extend('key%d' % i for i in range(1,6))
  16. csv_data = [[data[val][key] for key in all_keys] for val in data.keys()]
  17. with open('test.csv','w+') as outfile:
  18.     write = csv.writer(outfile)
  19.     write.writerows(csv_data)
  20.  
  21. json_file.close()
  22. output.close()
Advertisement
Add Comment
Please, Sign In to add comment