Skip to content

Instantly share code, notes, and snippets.

@louis030195
Last active September 30, 2020 14:53
Show Gist options
  • Save louis030195/0f5f850b1f2f6d3a571be30b49e46776 to your computer and use it in GitHub Desktop.
Save louis030195/0f5f850b1f2f6d3a571be30b49e46776 to your computer and use it in GitHub Desktop.
JSON to YAML, one liner bash
#!/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
@louis030195
Copy link
Author

usage:
chmod +x json_to_yaml.sh && ./json_to_yaml.sh my_json.json my_yaml.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment