mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge pull request #261 from YunoHost/add-sort_keys-and-indent-to-write_to_json
add options to write_to_json
This commit is contained in:
commit
4bcaf99204
1 changed files with 2 additions and 2 deletions
|
@ -193,7 +193,7 @@ def append_to_file(file_path, data):
|
||||||
write_to_file(file_path, data, file_mode="a")
|
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
|
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
|
# Write dict to file
|
||||||
try:
|
try:
|
||||||
with open(file_path, "w") as f:
|
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:
|
except IOError as e:
|
||||||
raise MoulinetteError("cannot_write_file", file=file_path, error=str(e))
|
raise MoulinetteError("cannot_write_file", file=file_path, error=str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Reference in a new issue