<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_to_file(data, path):
 """Export extracted fields to json Appends .json to path if missing and generates json file in specified directory, if not then in root Parameters data : dict Dictionary of extracted fields path : str directory to save generated json file Notes ---- Do give file name to the function parameter path. Examples -------- """

    if path.endswith('.json'):
        filename = path
    else:
        filename = path + '.json'

    with codecs.open(filename, "w", encoding='utf-8') as json_file:
        for line in data:
            line['date'] = line['date'].strftime('%d/%m/%Y')
        print(type(json))
        print(json)
        json.dump(
            data, json_file, indent=4, sort_keys=True, default=myconverter, ensure_ascii=False
        )