Riju21

40_get_data_from_json

May 12th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import json
  2. import os
  3.  
  4. THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
  5. my_file = os.path.join(THIS_FOLDER, 'info.json')
  6.  
  7. with open(my_file) as f:
  8.     # data-load
  9.     dataLoad = json.load(f)
  10.  
  11. for info in dataLoad['information']:
  12.     # print data
  13.     print(info['name'], '-' ,info['zip-code'])
  14.  
  15.  
  16.  
  17. # write data in file:
  18. # ----------------------
  19.  
  20. with open('E:/code/python/begin/41_json/write_data_in_file.json', 'w') as f1:
  21.     json.dump(dataLoad, f1, indent=2)
Advertisement
Add Comment
Please, Sign In to add comment