Created
          April 25, 2015 19:58 
        
      - 
      
- 
        Save hbillings/e68b6077b15b02e9fb6e to your computer and use it in GitHub Desktop. 
    Read a CSV, spit out JSON for D3
  
        
  
    
      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
    
  
  
    
  | import csv | |
| import json | |
| is_first_line = True | |
| input_file_name = "your_file_here.csv" | |
| output_file_name = "arrays.json" | |
| output_json_obj = open(output_file_name, "wb") | |
| with open(input_file_name, "rb") as file: | |
| csv_data = csv.reader(file) | |
| output_json_obj.write("[") | |
| for row in csv_data: | |
| if is_first_line == False: | |
| output_json_obj.write(",") | |
| else: | |
| is_first_line = False | |
| json.dump(row, output_json_obj) | |
| output_json_obj.write("]") | |
| output_json_obj.close() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment