Skip to content

Instantly share code, notes, and snippets.

@oguzhanaslann
Last active May 26, 2025 11:36
Show Gist options
  • Select an option

  • Save oguzhanaslann/0205317ed7ed227a4afca6c33afa98e5 to your computer and use it in GitHub Desktop.

Select an option

Save oguzhanaslann/0205317ed7ed227a4afca6c33afa98e5 to your computer and use it in GitHub Desktop.
Simple function to convert csv file into jsonl files written in python
import csv
import json
import argparse
def convert_csv_to_jsonl(input_csv, output_jsonl):
try:
# Open the CSV file
with open(input_csv, 'r', encoding='utf-8') as csv_file:
# Read CSV file
csv_reader = csv.DictReader(csv_file)
# Open the JSONL file for writing
with open(output_jsonl, 'w', encoding='utf-8') as jsonl_file:
# Convert each row to JSON and write to the output file
for row in csv_reader:
# Convert the row to JSON and write it as a line
jsonl_file.write(json.dumps(row, ensure_ascii=False) + '\n')
print(f"Successfully converted {input_csv} to {output_jsonl}")
except Exception as e:
print(f"An error occurred: {str(e)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment