Desired output:
{"MainKey":
[{"key01":"value01","key02":"value02"},
{"key11":"value11","key22":"value02"}
]
}
The code I tried:
data = {}
data2=[{}]
data2[0]['key01'] = 'value01'
data2[0]['key02']= 'value02'
data2[1]['key11'] = 'value11' #index out of bounds error
data2[1]['key12']= 'value12'
data['MainKey']=data2
import json
with open('try.json", 'w') as outfile:
json.dump(data,outfile)
But this gives index out of bounds error for the second set of values in data2. How do i solve this?
data2try:data2=[{}, {}]