I don’t remember exactly where I got these one-liners from anymore. It’s been in my expander for a while. Here are useful oneliners to convert JSON to YAML and vice versa.

JSON to YAML (stdout):

ruby -ryaml -rjson -e 'puts YAML.dump(JSON.load(ARGF))' < example.json

JSON to YAML (redirect to file):

ruby -ryaml -rjson -e 'puts YAML.dump(JSON.load(ARGF))' < example.json > example.yml

YAML to JSON (stdout):

ruby -ryaml -rjson -e 'puts YAML.dump(JSON.load(ARGF))' < example.yml

YAML to JSON (redirect to file):

ruby -ryaml -rjson -e 'puts YAML.dump(JSON.load(ARGF))' < example.yml > example.json

Hope you found this helpful! 🎉