Mam pewne problemy z generowaniem konkretnego obiektu JSON w pythonie.JSON - Generowanie jsona w pętli w pytonie
Muszę go mieć w tym formacie:
[
{"id":0 , "attributeName_1":"value" , "attributeName_2":"value" , .... },
{"id":1 , "attributeName_2":"value" , "attributeName_3":"value" , .... },
.
.
.
]
W Pythonie im coraz IDS attributeNames i wartości z 2 obiektów. Im próbuje wygenerować json tak:
data=[]
for feature in features_selected:
data.append({"id":feature.pk})
for attribute in attributes_selected:
if attribute.feature == feature:
data.append({attribute.attribute.name : attribute.value})
jsonData=json.dumps(data)
ale mam ten wynik, który nie jest dokładnie to, czego potrzebuję:
[
{"id":0} , {"attributeName_1":"value"} , {"attributeName_2":"value"} ,
{"id":1} , {"attributeName_2":"value"} , {"attributeName_3":"value"} , .... },
.
.
.
]