Reputation: 345
My json file is a list of dictionaries
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
Upvotes: 0
Views: 3322
Reputation: 60024
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 "the_dict"
then "words"
to get the list of words:
my_words = config_file[0]["the_dict"]["words"]
Upvotes: 4