I want to change the values in a json file. The json file contents are commented out. I want to change the values individually with having to write to the file separately for each value.
import json
"""
{
"keys": {
"developer": {},
"personal": {
"api_key": "1234567890",
"client_id": "9876543210",
"client_secret": "ncjegcbcncwkwdcowdch"
}
}
}
"""
json_file = "/home/api_keys.json"
with open(json_file) as json_data:
data = json.load(json_data)
with open(json_file, "w") as jsonFile:
json.dump(data, jsonFile)
data["keys"]["personal"]["api_key"] = "9999"
with open(json_file, "w") as jsonFile:
json.dump(data, jsonFile)
data["keys"]["personal"]["client_id"] = "000000000000"
with open(json_file, "w") as jsonFile:
json.dump(data, jsonFile)
data["keys"]["personal"]["client_secret"] = "hyfgdjocoduxbxlwowichcnckw"
with open(json_file) as json_data:
data = json.load(json_data)
api_key = data["keys"]["personal"]["api_key"]
client_id = data["keys"]["personal"]["client_id"]
client_secret = data["keys"]["personal"]["client_secret"]