Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created August 21, 2020 15:00
Show Gist options
  • Save ynonp/c5595a8fdf09c60c478d4afe3d95eb51 to your computer and use it in GitHub Desktop.
Save ynonp/c5595a8fdf09c60c478d4afe3d95eb51 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'csv'
require 'json'
def print_as_json(data)
$/ = "\n"
csv = CSV.new(data, :headers => true, liberal_parsing: true)
puts csv.to_a.map {|row| row.to_hash }.to_json
$/ = "---===---"
rescue
end
$/ = "---===---";
ARGF.each do |record|
record.chomp!("\n---===---")
record.delete_prefix!("\n")
print_as_json(record)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment