I have a weird scenario where I need to convert the string like "data["data"]["name"][0]" into a dict variable which can be used to modify the dict variable value
so
input. - "data["data"]["name"][0]"
and
output - data["data"]["name"][0]
so that I can use it modify the value of the variable.
Things that I have tried are locals() and globals() way of converting string to Variable but they seems to be failing given the string will actually be a complex dict variable.
update1:-
I was trying to get all the keys(path to keys) of a complex nested json and ended up getting that using collections and strings. so each key's path is string "data["data"]["name"][0]"
but to modify the complex json I would need to interpret this as variable and assign value.
sample code
var = "data['data']['name'][0]"
data = {"data":{"name":["test","tst2"]}}
print(data['data']['name'][0])
print(var) # this prints the string
print(eval(var)) # this prints the value of string evaluted or like get method
#how to set value using var variable
#means var should be like data['data']['name'][0]