mcve :
d1 = {"a":1}
d2 = {"b":2}
import json
with open('test2.json','w+') as file:
for d in [d1,d2]:
json.dump(d,file)
test2.json content :
{"a": 1}{"b": 2}
Desired Result :
[{"a": 1},{"b": 2}]
How can I achieve it?
Create a list instead, and dump that list directly.
with open('test2.json','w+') as file:
d = [d1, d2]
json.dump(d,file)