Skip to content

Instantly share code, notes, and snippets.

@potomak
Created August 4, 2010 12:28
Show Gist options
  • Save potomak/508057 to your computer and use it in GitHub Desktop.
Save potomak/508057 to your computer and use it in GitHub Desktop.
import csv
import json
f = open( 'photos.csv', 'r' )
reader = csv.DictReader( f, fieldnames = ( "thumbpath", "imgpath", "imgsrc", "width", "height", "thumbsrc", "thumbwidth", "thumbheight" ) )
out = json.dumps( [ row for row in reader ] )
print out
# CSV require
require 'csv'
# JSON require
require 'rubygems'
require 'json'
array = []
CSV.open('photos.csv', 'r', ',') do |row|
array << row.collect { |e| e.to_s }
end
p array.to_json
thumbpath imgpath imgsrc width height thumbsrc thumbwidth thumbheight
thumbnails/ images/ paris_01.jpg 350 262 paris_01.jpg 75 56
thumbnails/ images/ paris_02.jpg 262 350 paris_02.jpg 75 56
thumbnails/ images/ paris_03.jpg 350 262 paris_03.jpg 75 56
thumbnails/ images/ paris_04.jpg 262 350 paris_04.jpg 56 75
thumbnails/ images/ paris_05.jpg 262 350 paris_05.jpg 56 75
thumbnails/ images/ paris_06.jpg 350 262 paris_06.jpg 75 56
thumbnails/ images/ paris_07.jpg 262 350 paris_07.jpg 56 75
thumbnails/ images/ paris_08.jpg 262 350 paris_08.jpg 56 75
thumbnails/ images/ paris_09.jpg 262 350 paris_09.jpg 56 75
thumbnails/ images/ paris_10.jpg 350 262 paris_10.jpg 75 56
thumbnails/ images/ paris_11.jpg 350 262 paris_11.jpg 75 56
thumbnails/ images/ paris_12.jpg 350 262 paris_12.jpg 75 56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment