From cd8984cc0aaa1b91be04e51f98719e8a4c56aa9b Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Wed, 29 Jul 2026 20:11:14 +0200 Subject: [PATCH] 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 --- src/lerobot/utils/io_utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lerobot/utils/io_utils.py b/src/lerobot/utils/io_utils.py index e037b412c..3ef793a28 100644 --- a/src/lerobot/utils/io_utils.py +++ b/src/lerobot/utils/io_utils.py @@ -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)