From 1022db1732db1c32cfb974a66e2d59ca45b4cf3e Mon Sep 17 00:00:00 2001 From: l02 Date: Thu, 17 Oct 2024 14:23:47 +0300 Subject: [PATCH 1/2] improved write json method --- host_tools/utils/File.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/host_tools/utils/File.py b/host_tools/utils/File.py index 0cc6c23..b23ca6c 100644 --- a/host_tools/utils/File.py +++ b/host_tools/utils/File.py @@ -240,10 +240,17 @@ def read_json(path_to_json: str, encoding: str = "utf_8_sig") -> json: return json.load(file) @staticmethod - def write_json(path: str, data: "dict | list", mode: str = 'w', indent: int = 2) -> None: - Dir.create(dirname(path)) - with open(path, mode) as file: - json.dump(data, file, indent=indent) + def write_json( + path: str, + data: "dict | list", + mode: str = 'w', + indent: int = 2, + ensure_ascii: bool = True, + encoding='utf-8' + ) -> None: + Dir.create(dirname(path), stdout=False) + with open(path, mode, encoding=encoding) as file: + json.dump(data, file, ensure_ascii=ensure_ascii, indent=indent) @staticmethod def unpacking(archive_path: str, execute_path: str, delete_archive: bool = False, stdout: bool = True) -> None: From e707a7bd9efa73e156273a4c6548e5234375cb00 Mon Sep 17 00:00:00 2001 From: l02 Date: Thu, 17 Oct 2024 14:25:41 +0300 Subject: [PATCH 2/2] improved write json method --- host_tools/utils/File.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host_tools/utils/File.py b/host_tools/utils/File.py index b23ca6c..dccd99f 100644 --- a/host_tools/utils/File.py +++ b/host_tools/utils/File.py @@ -246,7 +246,7 @@ def write_json( mode: str = 'w', indent: int = 2, ensure_ascii: bool = True, - encoding='utf-8' + encoding: str = 'utf-8' ) -> None: Dir.create(dirname(path), stdout=False) with open(path, mode, encoding=encoding) as file: