📝 BLOG.IK.AM

@making's memo
(🗃 Categories 🏷 Tags)

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

🗃 {Programming/Ruby}

🏷 JSON 🏷 Ruby 🏷 YAML

🗓 Updated at 2018-07-24T15:20:19Z by Toshiaki Maki  🗓 Created at 2018-07-17T03:08:06Z by Toshiaki Maki  {✒️️ Edit  ⏰ History}


⚠️ Caution: This content is a bit old. Please be careful to read.

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))'