1import json # Imports the json file that we need
2with open("jsonfile.json", "r") as jsonFile: # Opens Json file for reading
3 data = json.load(jsonFile) # Reads Json file using json.load() method
4'''
5Example Json File:
6[{"name": "Bill", "age": 20},
7{"name": "Mary", "age": 31},
8{"name": "Jake", "age": 19}]
9'''
10data[1]["age"] = 32 # Alters data variable
11'''
12Now the data variable is:
13[{"name": "Bill", "age": 20},
14{"name": "Mary", "age": 32},
15{"name": "Jake", "age": 19}]
16'''
17with open("jsonfile.json", "w") as fileJson: # Opens Json file once again
18 json.dump(data, fileJson) # Replaces the Json file using json.dump() method