diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2020-01-26 08:14:32 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2020-01-26 08:14:32 +0100 |
commit | ea424f096c05a9587ffaa0bc6e5392790a046bd7 (patch) | |
tree | 01d0f9c596ebea229e6a8e2774a7a69a502a3488 /tests/yaml2json.py | |
parent | 02b452a86d11655002fdfbb1566ef494e2c954d2 (diff) | |
download | ufo-roof-ea424f096c05a9587ffaa0bc6e5392790a046bd7.tar.gz ufo-roof-ea424f096c05a9587ffaa0bc6e5392790a046bd7.tar.bz2 ufo-roof-ea424f096c05a9587ffaa0bc6e5392790a046bd7.tar.xz ufo-roof-ea424f096c05a9587ffaa0bc6e5392790a046bd7.zip |
Build ROOF sinograms
Diffstat (limited to 'tests/yaml2json.py')
-rw-r--r-- | tests/yaml2json.py | 19 |
1 files changed, 19 insertions, 0 deletions
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)) |