I have this sample json file but Im unable to wor with the keys from my json file.
import json
people_string = """
{"widget": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}
"""
x = json.loads(people_string)
#print(x)
#print(type(x))
for a in x["widget"]:
print(a)
When I run this code i get as output:
debug
window
image
text
How can I access from "window": "title"?
I tried
for a in x['widget']:
print(a["window"])
but this gives me an error
print(x["widget"]["window"]["title"])