1import json
2
3with open('path_to_file/person.json') as f:
4 data = json.load(f)
5
6print(data)
1import json
2
3with open('file_to_load.json', 'r') as file:
4 data = json.load(file)
1import json
2
3with open('path_to_file/person.json') as f:
4 data = json.load(f)
5print(data)
6
7flx = json.dumps(data, ensure_ascii=False, indent=4)
8print(flx)
1import json
2
3# with json load (file)
4info = open('data.json',)
5res = json.load(info)
6print(res)
7print("Datatype after deserialization : " + str(type(res)))
8#>>> {'name': 'Dave', 'City': 'NY'}
9#>>> Datatype of the serialized JSON data : <class 'dict'>
1import json
2
3#reading
4with open(file_name, 'r') as f:
5 data = json.load(f)
6
7#writing
8with open(file_name, 'w') as f:
9 json.dump(data, f) #use indent to make easyer to read eg. indent = 4