def store_data ( data ) : with open ( url_json_path ) as json_file : try : json_file_data = load ( json_file ) json_file_data . update ( data ) except ( AttributeError , JSONDecodeError ) : json_file_data = data with open ( url_json_path , 'w' ) as json_file : dump ( json_file_data , json_file , indent = 4 , sort_keys = True )
how to append data to a json file python
Use this function to store data in a JSON file .
def store_data(data):
    """Use this function to store data in a JSON file.

    This function is used for loading up a JSON file and appending additional
    data to the JSON file.

    :param data: the data to add to the JSON file.
    :type data: dict
    """
    with open(url_json_path) as json_file:
        try:
            json_file_data = load(json_file)
            json_file_data.update(data)
        except (AttributeError, JSONDecodeError):
            json_file_data = data
    with open(url_json_path, 'w') as json_file:
        dump(json_file_data, json_file, indent=4, sort_keys=True)