Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to keep order in yaml files #9

Open
SimonHeimberg opened this issue Sep 15, 2017 · 1 comment
Open

Allow to keep order in yaml files #9

SimonHeimberg opened this issue Sep 15, 2017 · 1 comment

Comments

@SimonHeimberg
Copy link

SimonHeimberg commented Sep 15, 2017

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

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

@SimonHeimberg
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant