Last active
September 30, 2020 14:53
-
-
Save louis030195/0f5f850b1f2f6d3a571be30b49e46776 to your computer and use it in GitHub Desktop.
JSON to YAML, one liner bash
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
#!/bin/bash | |
python3 -m venv .my_super_env && # Yeah random name to avoid erasing local virtualenv | |
source .my_super_env/bin/activate && | |
pip install -q pyyaml && | |
python3 -c "import yaml, json, sys | |
sys.stdout.write(yaml.dump(json.load(sys.stdin)))" \ | |
< $1 > $2 || true | |
# Remove the temporary venv in any case | |
rm -rf .my_super_env || true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage:
chmod +x json_to_yaml.sh && ./json_to_yaml.sh my_json.json my_yaml.yml