Last active
December 7, 2018 14:16
-
-
Save xenithorb/e90713534624c93a834a92c2a0c6ee28 to your computer and use it in GitHub Desktop.
Bashrc-style functions for json2yaml and yaml2json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Please place these in ~/.bashrc or equivalent | |
yaml2json() { | |
python3 < "${1:-/dev/stdin}" <( | |
cat <<-EOF | |
import sys, yaml, json | |
json.dump(yaml.load(sys.stdin), sys.stdout, indent=4) | |
EOF | |
) | |
} | |
json2yaml() { | |
python3 < "${1:-/dev/stdin}" <( | |
cat <<-EOF | |
import sys, yaml, json | |
yaml.safe_dump( json.load(sys.stdin), | |
sys.stdout, | |
explicit_start=True, | |
default_flow_style=False | |
) | |
EOF | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment