I'm trying to append a list with new names in a json file.
JSON structure:
{
"users": [
"User1",
"User2",
"User3"
]
}
I have tried this:
with open('data/users.json', 'r') as json_file:
json_data = json.load(json_file)
user_list = json_data["users"]
with open('data/users.json', 'w') as json_file:
user_list.append(name)
json.dump(user_list, json_file)
But it turns out like this:
["User1", "User2", "User3", "User4"]
Why and how do I fix it?
json.dump(json_data, json_file)list, whereas the JSON data is more like adictionary?