How to assign a value to a dictionary key in Python, which is in the JSON file?

I have a JSON file that I wanted to be filled in by Python code. Now I can only record in the file, but not in the dictionary in it. Maybe someone knows how to fill a specific dictionary? Google did not help me. May properly formulate a question or don't understand something
April 4th 20 at 00:51
2 answers
April 4th 20 at 00:53
Solution
Bad Google. https://python-scripts.com/json
import json

with open("data_file.json", "r") as read_file:
 data = json.load(read_file)
Thank you. The article I saw, but did not help me - Raquel.Lan commented on April 4th 20 at 00:56
@Raquel.Lan, after prochitaete json via json.load() the output will be a simple vocabulary. Most often nested, sometimes using lists, but to work with them just as with a conventional dictionary. - waldo.Emard94 commented on April 4th 20 at 00:59
@waldo.Emard94, thank you! Used to think that you can change the dictionary in the JSON file without completely overwriting the dictionary. But, as I understand it, did not. Switched from JSON file to the database:) - Raquel.Lan commented on April 4th 20 at 01:02
@Raquel.Lan, DB is a good solution scales better than json. But just, if not much, then write back the json is not too difficult. Load the data into a dictionary using json.load() change the dictionary, and re-written to a file using json.dump(). - waldo.Emard94 commented on April 4th 20 at 01:05
@waldo.Emard94, Thank You! - Raquel.Lan commented on April 4th 20 at 01:08
April 4th 20 at 00:55
Solution
import json

with open("data_file.json", "r") as read_file:
 data = json.load(read_file)
 data[key] = value

Find more questions by tags PythonJSON