Look like you have been given this a task as homework.
With some Java code as a start and that you should write it Python.
So is this homework?
Just to give some hint on a start.
What the json file return is Python dictionary,here is it normal to have a mix of dict and list as your data show.
Can use direct access or a get method as the Java code has.
With some Java code as a start and that you should write it Python.
So is this homework?
Just to give some hint on a start.
jk91 Wrote:Step 1: You have to read the file, If any Error, please correct.
import json with open("data.json", "r") as read_file: data = json.load(read_file)This read the json file,look into
try:except
for catching error.What the json file return is Python dictionary,here is it normal to have a mix of dict and list as your data show.
Can use direct access or a get method as the Java code has.
>>> data {'age': 35, 'children': [{'age': 6, 'firstName': 'Alice'}, {'age': 8, 'firstName': 'Bob'}], 'firstName': 'Jane', 'hobbies': ['running', 'sky diving', 'singing'], 'lastName': 'Doe'} >>> # Direct access >>> data['children'][0]['firstName'] 'Alice' >>> >>> # Using get here can also do error check >>> data['children'][0].get('firstName', 'Not in Record') 'Alice' >>> data['children'][0].get('firstName9', 'Not in Record') 'Not in Record'