-
Notifications
You must be signed in to change notification settings - Fork 11
/
jsonl_csv_con.py
26 lines (20 loc) · 905 Bytes
/
jsonl_csv_con.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
import csv
# Function to read JSON data from a file and convert it to CSV format
def json_file_to_csv(json_file_path, csv_file_path):
# Read JSON data from the file
with open(json_file_path, 'r', encoding='utf-8') as json_file:
json_data = json.load(json_file)
# Open the CSV file for writing
with open(csv_file_path, mode='w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
# Writing the header of the CSV file
writer.writerow(["instruction", "input", "output"])
# Writing data rows
for entry in json_data:
writer.writerow([entry["instruction"], entry["input"], entry["output"]])
# Example JSON file path
json_file_path = 'llama-train.json' # Replace with the actual JSON file path
# Specify the CSV file path
csv_file_path = 'llama-train.csv'
json_file_to_csv(json_file_path, csv_file_path)