i want to update a list of array in json using python i have used this
import json
with open('test.json', 'w') as file:
d = {
"name": 'David',
"gender": 'Female'
}
data = json.load(file)
data.append(d)
json.dump(data, file)
and json file is test.json
[
{
"name": "John",
"gender": "Male"
},
{
"name": "Mary",
"gender": "Female"
}
]
when i run the code it shows
Traceback (most recent call last):
File "test.py", line 8, in <module>
data = json.load(file)
File "C:\Users\John\anaconda3\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
io.UnsupportedOperation: not readable
i want something like this and i have also tried by changing w to r and r+
[
{
"name": "John",
"gender": "Male"
},
{
"name": "Mary",
"gender": "Female"
},
{
"name": "David",
"gender": "Female"
}
]