I want to make a function that recives a data in a type of dictionary, and then appends that data to JSON file. This is how JSON file to looks like [{},{},{}] and after appending I want it to be [{},{},{},{}]. Function below is what I tried, if I use 'w', it overwrites, and if I use 'a', file after appending looks like this [{},{},{}{}] which isn't JSON anymore. How to achieve this?
def save_to_file(user_data):
f = open('users.json', 'a')
json.dump(user_data, f, indent=2)
f.close()