Convert JSON to YAML in one command

less than 1 minute read

I’ve been playing around with AWS CloudFormation recently, which supports both JSON and YAML. I prefer to use YAML, but a lot of the examples I was looking at were based in JSON. Fortunately there’s a quick way to convert a JSON file to it’s YAML equivalent.

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

Can’t remember where I found it, likely StackOverflow, anyway it’s a useful command to have!