Skip to content

Instantly share code, notes, and snippets.

@oyiptong
Created November 27, 2017 17:23
Show Gist options
  • Save oyiptong/1a7ebf24314bd6580612a760103d8ee1 to your computer and use it in GitHub Desktop.
Save oyiptong/1a7ebf24314bd6580612a760103d8ee1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'csv'
require 'json'
if ARGV.length == 0
puts "needs an argument. #{ARGV.length}"
exit(1)
end
rows =[]
file_data = File.read(ARGV[0])
CSV.new(file_data, col_sep: '{', headers: true, quote_char: '"').each do |row|
rows << row.to_hash
end
puts "output is:\n#{JSON.pretty_generate(rows)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment