From 2122e817c07ad4b4ef43764d813a19a5872cde81 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 18 Feb 2026 23:36:34 -0800 Subject: [PATCH] YAML/JSON: Preserve Insertation Order Keep insertation order when round-tripping to/from files. This is recommended because our dictionary keys are easier readable for humans that way. https://pals-project.readthedocs.io/en/latest/conventions.html#yaml-101 --- src/pals/functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pals/functions.py b/src/pals/functions.py index 4186f6f..cc6ad9a 100644 --- a/src/pals/functions.py +++ b/src/pals/functions.py @@ -63,14 +63,14 @@ def store_dict_to_file(filename: str, pals_dict: dict): if extension == ".json": import json - json_data = json.dumps(pals_dict, sort_keys=True, indent=2) + json_data = json.dumps(pals_dict, sort_keys=False, indent=2) with open(filename, "w") as file: file.write(json_data) elif extension == ".yaml": import yaml - yaml_data = yaml.dump(pals_dict, default_flow_style=False) + yaml_data = yaml.dump(pals_dict, default_flow_style=False, sort_keys=False) with open(filename, "w") as file: file.write(yaml_data)