Answer the question
In order to leave comments, you need to log in
How to complement json python, do you need code?
I get 3 data id, login, password in the telegram bot.
I need to correctly supplement this json file with this data, which is currently available
{
"id": {
"login": "login",
"password": "password"
}
}
Answer the question
In order to leave comments, you need to log in
my json breaks every time
import json
data = '''{
"id": {
"login": "login",
"password": "password"
}
}'''
json_data = json.loads(data)
json_data['1'] = {'login': 'log', 'password': 'pass'}
print(json.dumps(json_data, indent=4))
# {
# "id": {
# "login": "login",
# "password": "password"
# },
# "1": {
# "login": "log",
# "password": "pass"
# }
# }
Well, if it’s straight on the forehead, then parse json into a dict, add a new one and save it again
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question