How to write a nested dictionary to json
dictionary, json, nested, python
Solution
d = {
"Laptop": {
"sony": 1,
"apple": 2,
"asus": 5,
},
"Camera": {
"sony": 2,
"sumsung": 1,
"nikon" : 4,
},
}
with open("my.json","w") as f:
json.dump(d,f)
Problem
I created a nested dictionary in Python like this: ``` { "Laptop": { "sony": 1 "apple": 2 "asus": 5 }, "Camera": { "sony": 2 "sumsung": 1 "nikon" : 4 }, } ``` But I couldn't figure out how to write this nested dict into a json file. Any comments will be appreciated..!