From ad2874d7169ed086d87616aeef597a721238d6e7 Mon Sep 17 00:00:00 2001 From: Nikolai Lambrov <52069739+l8556@users.noreply.github.com> Date: Thu, 17 Oct 2024 14:28:12 +0300 Subject: [PATCH] improved write json method (#68) * improved write json method * 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..dccd99f 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: str = '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: