how to add to dict json in python code example

Example 1: write dict to json python

import json
with open('result.json', 'w') as fp:
    json.dump(sample, fp)

Example 2: insert json file in python

a_dictionary = {"d": 4}

with open("sample_file.json", "r+") as file:
    data = json.load(file)	# get data from file
    update(a_dictionary)
    seek(0)
    json.dump(data, file)	# insert data in file

Example 3: how to add items to an existing json file python

a_dictionary = {"d": 4}

with open("sample_file.json", "r+") as file:
    data = json.load(file)
    update(a_dictionary)
    seek(0)
    dump(data, file)