jyparser icon indicating copy to clipboard operation
jyparser copied to clipboard

Allow to keep order in yaml files

Open SimonHeimberg opened this issue 8 years ago • 1 comments

This is simple to implement by using the Loaders and Dumpers from here:

https://github.com/fmenabe/python-yamlordereddictloader

SimonHeimberg avatar Sep 15 '17 14:09 SimonHeimberg

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)'
}

SimonHeimberg avatar Sep 15 '17 14:09 SimonHeimberg