Skip to content

Instantly share code, notes, and snippets.

@Slackwise
Created January 29, 2014 20:25
Show Gist options
  • Save Slackwise/8696251 to your computer and use it in GitHub Desktop.
Save Slackwise/8696251 to your computer and use it in GitHub Desktop.
Converts a list of .csv files to .json files.
#!/usr/bin/env ruby
#
# Converts a list of .csv files to .json files.
require 'csv'
require 'json'
require 'pathname'
ARGV.each do |filename|
csv_file = Pathname.new(filename)
File.open(csv_file.basename.sub(/\.csv$/, '.json'), 'w') do |json_file|
json_file.write(CSV.read(csv_file).to_json)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment