JSON to YAML One Liner
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! 🎉
Thanks for reading this far. If you found this article useful, I'd really appreciate it if you share this article so others can find it too! Thanks 😁 Also follow me on Twitter.
Got questions? Check out BoltOps.
You might also like
Kubes: Kubernetes Deployment Tool
Kubes is a Kubernetes Deployment Tool. It builds the docker image, creates the Kubernetes YAML, and runs kubectl apply. It automates the deployment process and saves you precious finger-typing energy.
Jets: The Ruby Serverless Framework
Ruby on Jets allows you to create and deploy serverless services with ease, and to seamlessly glue AWS services together with the most beautiful dynamic language: Ruby. It includes everything you need to build an API and deploy it to AWS Lambda. Jets leverages the power of Ruby to make serverless joyful for everyone.
Lono: The CloudFormation Framework
Building infrastructure-as-code is challenging. Lono makes it much easier and fun. It includes everything you need to manage and deploy infrastructure-as-code.