Oct-02-2019, 11:44 AM
Hi,
i have the following json file contained in a file named file.conf
and i Need to replace the value of ENDPOINT witn something else
here is my Code
i have the following json file contained in a file named file.conf
and i Need to replace the value of ENDPOINT witn something else
{"azure":{"ENDPOINT":"x","DB":"y","COL":"can"},"cache":{"path":"\path"},"queue":{"q":10},"log":{"log":"info"}}}so i m trying to Access to this value first and set it to another value
here is my Code
with open('/home/file.conf', 'r') as file: json_data = json.load(file) print(type(json_data)) # it is a dictionnary for item in json_data: for data_item in item['azure']: data_item['ENDPOINT']="new value" with open('/home/file.conf', 'w') as file: json.dump(json_data, file, indent=2) #try to replace the file valuebut i m getting the following error
for data_item in item['azure']: TypeError: string indices must be integersany help?