Skip to content

Instantly share code, notes, and snippets.

@xenithorb
Last active December 7, 2018 14:16
Show Gist options
  • Save xenithorb/e90713534624c93a834a92c2a0c6ee28 to your computer and use it in GitHub Desktop.
Save xenithorb/e90713534624c93a834a92c2a0c6ee28 to your computer and use it in GitHub Desktop.
Bashrc-style functions for json2yaml and yaml2json
# 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