📝 BLOG.IK.AM

@making's memo
(🗃 Categories 🏷 Tags)

ワンライナーでJSON <-> YAMLの変換

🗃 {Programming/Ruby}

🏷 JSON 🏷 Ruby 🏷 YAML

🗓 Updated at 2018-07-25T00:20:19+09:00 by Toshiaki Maki  🗓 Created at 2018-07-17T12:08:06+09:00 by Toshiaki Maki  {✒️️ Edit  ⏰ History}


memo

JSON -> YAML

cat foo.json | ruby -ryaml -rjson -e 'puts YAML.dump(JSON.load(ARGF))'

YAML -> JSON

cat foo.yml | ruby -ryaml -rjson -e 'puts JSON.dump(YAML.load(ARGF))'

Pretty Printする場合は

cat foo.yml | ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))'