I have a Python file main.py
with the following code, but it is giving me error messages:
day_of_event = '1990-12-25'
shopping_list = ['bread', 'cereal', 'water', 'soda', 'bananas']
with open(store_items.json) as file:
json_file = json.loads(file)
report = json_file["report"]
report = json.dumps(report)
The following is the JSON file store_items.json
:
{
"report" : "{'title' : 'grocery_report', 'date' : day_of_event, 'grocery_items' : shopping_list}"
}
How can I read the JSON file store_items.json
and import the JSON variable "report" into the Python file so that the variable report
in the Python script is equivalent to the following?
report = {'title' : 'grocery_report', 'date' : '1990-12-25', 'grocery_items' : ['bread', 'cereal', 'water', 'soda', 'bananas']}