Created
August 21, 2020 15:00
-
-
Save ynonp/c5595a8fdf09c60c478d4afe3d95eb51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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