diff --git a/common/file.py b/common/file.py index 00a232c9dee19d08b29c37aed0b7ee5173376574..21457b72dc9a9cac361eeffe565b5b8ae2f0f672 100644 --- a/common/file.py +++ b/common/file.py @@ -3,6 +3,7 @@ # cython:language_level=3 import io +import json5 import os from common.config import Config @@ -43,4 +44,14 @@ class FileOperation: full_file_name = Config.get_output_path() + file_name with io.open(full_file_name, mode='a', encoding='utf-8') as file_obj: file_obj.write(data) - \ No newline at end of file + + @staticmethod + def write_json_file(data_dict, file_name): + ''' + Write dict type content to json file + ''' + full_file_name = file_name + js_obj = json5.dumps(data_dict, indent=4) + full_file_name = Config.get_output_path() + file_name + with io.open(full_file_name, mode='a', encoding='utf-8') as file_obj: + file_obj.write(js_obj)