I want to update a JSON file in a for loop
In the for loop I have following code:
with open('immodata.json', 'a') as file:
json.dump([{'preis' : priceList, 'plz' : plzList, 'zimmer' : roomList, 'wohnflaeche' : sqrList} for priceList, plzList, roomList, sqrList in zip(priceList, plzList, roomList, sqrList)], file)
The problem is this is adding the new Data as sole Data instead of continuing the JSON.
What I get:
[{"preis": "1750000", "plz": "5222", "zimmer": "5.5", "wohnflaeche": "185"}][{"preis": "1750000", "plz": "5222", "zimmer": "5.5", "wohnflaeche": "185"}]
What I want:
[{"preis": "1750000", "plz": "5222", "zimmer": "5.5", "wohnflaeche": "185"}, {"preis": "1650000", "plz": "5222", "zimmer": "5.5", "wohnflaeche": "155"}
I assume I have to read out the file, add the new data to the list, and then append to the JSON File, but I did not find out how I would to this.
