From ea424f096c05a9587ffaa0bc6e5392790a046bd7 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Sun, 26 Jan 2020 08:14:32 +0100 Subject: Build ROOF sinograms --- tests/yaml2json.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/yaml2json.py (limited to 'tests/yaml2json.py') diff --git a/tests/yaml2json.py b/tests/yaml2json.py new file mode 100644 index 0000000..e97b472 --- /dev/null +++ b/tests/yaml2json.py @@ -0,0 +1,19 @@ +import sys +import yaml +import json +from collections import OrderedDict + +def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict): + class OrderedLoader(Loader): + pass + def construct_mapping(loader, node): + loader.flatten_mapping(node) + return object_pairs_hook(loader.construct_pairs(node)) + OrderedLoader.add_constructor( + yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, + construct_mapping) + return yaml.load(stream, OrderedLoader) + +#obj = json.load(sys.stdin, object_pairs_hook=OrderedDict) +obj = ordered_load(sys.stdin, yaml.SafeLoader) +print(json.dumps(obj, indent=4, sort_keys=False)) -- cgit v1.2.3