So I'm struggling on adding an element to a json list that's saved on my machine. What I'm trying to is the json will update with the user's typed message. However I'm getting the error of "JSONDecodeError: Expecting value: line 1 column 1 (char 0)"
with open(JSON_FILE, "r+") as data_file:
data = json.load(data_file)
data[0]['test'].append(enteredString)
json.dump(data, data_file)
Here is the Json I'm trying to update.
{"test": [
"test 1",
"test 2"
]}
I want it so that the new saved json file will be.
{"test": [
"test 1",
"test 2",
"New String"
]}
I can't figure out what I'm doing wrong, any help would be appreciated.
data = json.load(data_file)the line throwing the error?). If you were able to load the file with json then you would dodata['test'].append(enteredString); the list is contained as a value against thetestkey, so the indexing won't work.