From c1669174c3ee370af8fe1fd9f242e7a97c0c86bb Mon Sep 17 00:00:00 2001 From: Kay0u Date: Fri, 11 Dec 2020 15:08:31 +0100 Subject: [PATCH] add options to write_to_json --- moulinette/utils/filesystem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moulinette/utils/filesystem.py b/moulinette/utils/filesystem.py index b7580b2c..15bf1c3b 100644 --- a/moulinette/utils/filesystem.py +++ b/moulinette/utils/filesystem.py @@ -193,7 +193,7 @@ def append_to_file(file_path, data): write_to_file(file_path, data, file_mode="a") -def write_to_json(file_path, data): +def write_to_json(file_path, data, sort_keys=False, indent=None): """ Write a dictionnary or a list to a json file @@ -222,7 +222,7 @@ def write_to_json(file_path, data): # Write dict to file try: with open(file_path, "w") as f: - json.dump(data, f) + json.dump(data, f, sort_keys=sort_keys, indent=indent) except IOError as e: raise MoulinetteError("cannot_write_file", file=file_path, error=str(e)) except Exception as e: