fix(utils): allow any JSON payload in write_json - #3993 (#4217)

* fix(utils): allow any JSON payload in write_json

The dict-only type stub blocked lists/scalars callers already dump.
Accept Any, set utf-8 encoding, and cover list roundtrip.

* fix(utils): json type

---------

Co-authored-by: Bartok9 <danielrpike9@gmail.com>
This commit is contained in:
Steven Palma
2026-07-29 20:11:14 +02:00
committed by GitHub
parent b9ded9e761
commit cd8984cc0a
+5 -5
View File
@@ -32,21 +32,21 @@ def load_json(fpath: Path) -> Any:
Returns:
Any: The data loaded from the JSON file.
"""
with open(fpath) as f:
with open(fpath, encoding="utf-8") as f:
return json.load(f)
def write_json(data: dict, fpath: Path) -> None:
"""Write data to a JSON file.
def write_json(data: JsonLike, fpath: Path) -> None:
"""Write JSON-serializable data to a file.
Creates parent directories if they don't exist.
Args:
data (dict): The dictionary to write.
data: JSON-serializable data to write.
fpath (Path): The path to the output JSON file.
"""
fpath.parent.mkdir(exist_ok=True, parents=True)
with open(fpath, "w") as f:
with open(fpath, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)