
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! 🎉
Tutorials to help your journey in the DevOps and Infrastructure-as-Code world.
The best way to learn is by doing. You retain information better when to do. BoltOps Learn videos helps you learn how to build actual things. You'll thank yourself.
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.