I want to extract the value out of nested dictionary in python. The main issue is I want to pass the extraction set as a string from config file where a user can pass their own command and we extract the value out of it. Dictionary is something like
d = {"a": {"b": [ {"c": "apple"}]}}
I want to extract the value of c but I want to pass the command as a string from outside possibly a config file which gives user control to extract whichever information they want.
For example a user can pass string "['a']['b'][0]['c']" or user can pass ['a']['b'] or anything and we return the value present in the dict on that path
Now I know there is eval present in python. But is there a better way that this? I have tried using eval and it works fine but as we all know they are evil and should be avoided. Is there a better way