save data in a json flie without overwriting existing file in python

i need to add data in an json file without overwriting.

the code am using is:

import json

data=[]

def arr():
x=0
while x<1:
print(x)
x-=1
X.append(x)
data.update(x)
with open(‘x.txt’,‘w’)as outfile:
json.dump(data,outfile)

arr()
print(X)

this one works file.But,while am running this code second time it overwrites the existing values in the text file.help me to solve this code

#json #arrays #python

6 Likes67.80 GEEK