Skip to content

Commit

Permalink
improved write json method (#68)
Browse files Browse the repository at this point in the history
* improved write json method

* improved write json method
  • Loading branch information
l8556 authored Oct 17, 2024
1 parent 72c2d5d commit ad2874d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions host_tools/utils/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ad2874d

Please sign in to comment.