Tested in Spyder 3.3.3 (for Python 3.7).
employees.json
{ "employee_data": [ { "lname": "Jackson", "fname": "Eddie", "email": "EJackson@domain.com", "address": "1111 Right Lane", "title": "Engineer" }, { "lname": "Johnson", "fname": "Darrin", "email": "DJohnson@domain.com", "address": "2222 Left Lane", "title": "IT Manager" }, { "lname": "Lee", "fname": "Keith", "email": "KLee@domain.com", "address": "3333 Middle Lane", "title": "Executive Assistant" } ] }
employees.py
# MrNetTek # eddiejackson.net/blog # 9/8/2020 # free for public use # free to claim as your own import json # Opening JSON file file = open('employees.json',) # Build dictionary #data = json.load(file) # Read JSON file data = json.loads(file.read()) # Iterate through JSON data for employee in data['employee_data']: # Display employee data print(employee) # Close JSON file file.close()
Output
{‘lname’: ‘Jackson’, ‘fname’: ‘Eddie’, ’email’: ‘EJackson@domain.com’, ‘address’: ‘1111 Right Lane’, ‘title’: ‘Engineer’}
{‘lname’: ‘Johnson’, ‘fname’: ‘Darrin’, ’email’: ‘DJohnson@domain.com’, ‘address’: ‘2222 Left Lane’, ‘title’: ‘IT Manager’}
{‘lname’: ‘Lee’, ‘fname’: ‘Keith’, ’email’: ‘KLee@domain.com’, ‘address’: ‘3333 Middle Lane’, ‘title’: ‘Executive Assistant’}