Reputation: 592
I want to convert a CSV file into ruby hash. I am handling a nested hash using dots in csv header. For example, user.name
as CSV header with cell value "john"
is converted into:
{"user" => {"name" => "john"}}
How should I represent an array of hash in my CSV? I want a hash like this:
{"scores" => [{"maths" => "60"},{"science" => "50"} ]}
I do not know what the CSV header/value format should be to get the hash above. Any ideas will be helpful.
Upvotes: 0
Views: 688
Reputation: 2576
Depending on the amount of data you want in each array, you could have a scores.maths
header and scores.science
header and then find the same keys when parsing the header row, in this case scores
and build your array from that.
Upvotes: 1