I am able to successfully open it but I am not sure how to access the “the_dict” dictionary so I can retrieve and print just “test” and “pie” in my python program.
with open('my_settings.json') as json_data: config = json.load(json_data) # my_words = config["the_dict"] is what I tried but this does not work
config_file is a list, not a dictionary, as you have observed. You will need to access the first dictionary in the list, and then call the key
"words" to get the list of words:
my_words = config_file["the_dict"]["words"]
Sorry to hitchhike this post but I’m trying to do the exact opposite… I’m looking to format some Python code to create a JSON file in this format – anyone have a thought on this?