I need to load a json and read the content to edit it later. I am getting
{TypeError}string indices must be integers
here is the json structure (note-below is the format when json file is already loaded, else it shows double quotes)
data ={'a':'hello','b':'{"date1":"9/21/2021","date2":"9/22/2021"}','c':'new'}
when trying to access data['b']['date1']
it throws error
code is as follows
jsonfile=open(file.json, "r")
data = json.load(jsonfile)
jsonfile.close()
date = data['b']['date1']
'b'’s key is a string, not a dict. You can use theast.literal_evalfunction orjsonlibrary to convert the string into a dict.