Last active
August 10, 2022 15:57
-
-
Save lwoodson/a9421897b9ab85e395117b90269848da to your computer and use it in GitHub Desktop.
Convert JSON to YAML via stdin (Ruby)
This file contains hidden or 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
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o xtrace | |
sudo cat > /usr/local/bin/json2yaml <<EOT | |
#!/usr/bin/env ruby | |
require 'json' | |
require 'yaml' | |
input = ARGF.read() | |
json = JSON.load(input) | |
yaml = YAML.dump(json) | |
print yaml | |
EOT | |
sudo chmod +x /usr/local/bin/json2yaml |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'json' | |
require 'yaml' | |
input = ARGF.read() | |
json = JSON.load(input) | |
yaml = YAML.dump(json) | |
print yaml |
Probably easier ways, but #$%$ it.
Or as a one-liner shell alias:
alias json2yml="ruby -rjson -ryaml -e 'print YAML.dump(JSON.load(ARGF.read()))'"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
install
use