Im creating dict from database entries:
result = []
for row in rows:
d = dict()
d['first'] = row[0]
d['second'] = row[1]
result.append(json.dumps(d, indent=3, default=str))
result:
{'first': 1, 'second': 2 }
and everything looks nice but I want to add array to this dict and it should looks like below:
{'first': 1, 'second': 2, 'third': [{'somekey': row[2]}] }
and I dont know how to handle it
result = []
for row in rows:
d = dict()
d['first'] = row[0]
d['second'] = row[1]
d['third'] = []
d['third'][somekey] = row[2]
result.append(json.dumps(d, indent=3, default=str))
but it doesn't work