From a89d3dcd06ee27381beaefdff26d8c851f8a8a77 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 31 Aug 2026 14:40:45 +0200 Subject: [PATCH] misc.store_dict(): Add function Add a store_dict() function to write the contents of a mapping to a file as JSON, using the same formatting as dump_dict(). Signed-off-by: Jan Lindemann --- src/python/jw/util/misc.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/python/jw/util/misc.py b/src/python/jw/util/misc.py index 58a0705..46d4b10 100644 --- a/src/python/jw/util/misc.py +++ b/src/python/jw/util/misc.py @@ -251,6 +251,19 @@ def dump_dict( # export log.log(prio, f'| {line}', caller = caller) log.log(prio, f'`{header}', caller = caller) +def store_dict(path: str, d: Mapping[str, Any]) -> None: # export + import json + with open(path, 'w') as f: + f.write( + json.dumps( + d, + sort_keys = True, + ensure_ascii = False, + indent = 4, + separators = (',', ': '), + ) + ) + def dump( # export prio: int, objects: Iterable[Any], *args: Any, **kwargs: Any ) -> None: