From: brabuhr@... Date: 2011-01-12T10:38:16+09:00 Subject: Re: Migrate data from .csv to .yml > Does anyone has any parsers or examples or guidelines on how to convert > csv data into YAML (.yml) format? I counldnt find any appropriate > guideline that explains how to do this. Any link or example that > explains how to do this is welcomed. Thanks Bare bones: irb(main):001:0> require 'csv' => true irb(main):002:0> z = CSV.read('foo.csv', :headers => true) => # irb(main):003:0> require 'yaml' => true irb(main):004:0> puts z.to_yaml --- !ruby/object:CSV::Table mode: :col_or_row table: - !ruby/object:CSV::Row header_row: false row: - - a - "1" - - b - "2" - - c - "3" - !ruby/object:CSV::Row header_row: false row: - - a - "4" - - b - "5" - - c - "6" - !ruby/object:CSV::Row header_row: false row: - - a - "7" - - b - "8" - - c - "9" Though, I imagine you have some other idea of how the yaml should be structured; so, the idea could be to loop through each row in the CSV, build e.g. a Hash that looks like what you want, append that hash to an Array, and then dump that Array to_yaml. (Somewhat like what Johnny posted while I was typing this paragraph :-)