I want to update my json file using a python script, however the json in the .json file is inside of an array [] it looks like this:
[
{
"test": "2",
"test1": "1"
},
{
"test2": "3",
"test3": "4"
}
]
So far I've tried:
username = "test"
with open("file.json", "a+") as f:
json_file = json.load(f)
json_file[0]['username'] = username
json.dump(json_file, f)
error:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)```
.jsonyou have provided.usernametestandtest1, both inside a new object inside the arraya+. You're starting at the end of the file, and sojson.load()has nothing to read.