Skip to content

Instantly share code, notes, and snippets.

@otzoran
Last active October 17, 2017 08:48
Show Gist options
  • Save otzoran/c5cc4f2017367169e6975919c5fb0440 to your computer and use it in GitHub Desktop.
Save otzoran/c5cc4f2017367169e6975919c5fb0440 to your computer and use it in GitHub Desktop.
json2yaml and yaml2json oneliners using ruby

Add to bashrc

alias yaml2json="ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))'"
alias json2yaml="ruby -ryaml -rjson -e 'puts YAML.dump(JSON.parse(STDIN.read))'"

WIIG4

take a horrible json (such as packer template), convert it to yaml, edit it (vi, sed, awk) and convert back

side dish

Pipe the json through jq; the default is a colorized output making it easier to examine

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