0

My json file is a list of dictionaries enter image description here

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

1 Answer 1

4

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"]
Sign up to request clarification or add additional context in comments.

1 Comment

my_words = config_file[0]["the_dict"]["words"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.