I have made a small python program which writes some string inputs into a JSON file:
import json
while True:
name = input('What is your name?')
surname = input('What is your surname')
age = input('How old are you?')
with open("info_.json", "w") as data:
information = {name: {'surname': surname, 'age': age}}
data.write(json.dumps(information))
data.close()
with open("info_.json", "r") as info_read:
dict_info = json.loads(info_read.read())
name_d = dict_info.get(name)
print(name_d)
It works perfectly fine, althought the second time of the loop, the inputs overwrite the information that was written the first time. Is there any way of adding more data to a file, without overwriting? Thank you
with open("info_.json", 'a')method?