JSON list of dictionaries to python

Question:

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
Asked By: MMM

||

Answers:

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"]
Answered By: TerryA

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?

Answered By: Steph Flint
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.