jyparser
jyparser copied to clipboard
Allow to keep order in yaml files
This is simple to implement by using the Loaders and Dumpers from here:
https://github.com/fmenabe/python-yamlordereddictloader
Managed to get it working. Here the two changed functions:
y2j() {
python -c 'import sys, yaml, json, yamlordereddictloader; json.dump(yaml.load(sys.stdin, Loader=yamlordereddictloader.SafeLoader), sys.stdout, indent=4)'
}
j2y() {
python -c 'import sys, yaml, json, yamlordereddictloader, collections; yaml.dump(json.load(sys.stdin, object_pairs_hook=collections.OrderedDict), sys.stdout, indent=4, default_flow_style=False, Dumper=yamlordereddictloader.SafeDumper)'
}