dart_llm_tasks_pretty / data /format_change.py
YongdongWang's picture
initial commit
c0670d3
# Conversion mode: 'pretty' for JSONL -> pretty JSON, 'jsonl' for pretty JSON -> JSONL
mode = 'jsonl' # change to 'jsonl' to reverse the conversion
import os
import json
if mode == 'pretty':
# Step 1: Read original JSONL
with open("data/dart_llm_tasks.jsonl", encoding="utf-8") as f:
data = [json.loads(line) for line in f]
# Ensure output directory exists
os.makedirs("data", exist_ok=True)
# Step 2: Write pretty JSON array with indentation
with open("data/dart_llm_tasks_pretty.json", "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
elif mode == 'jsonl':
# Step 1: Read pretty JSON array
with open("data/dart_llm_tasks_pretty.json", encoding="utf-8") as f:
data = json.load(f)
# Step 2: Write back to JSONL (one object per line)
with open("data/dart_llm_tasks.jsonl", "w", encoding="utf-8") as f:
for item in data:
f.write(json.dumps(item, ensure_ascii=False) + "\n")
else:
raise ValueError("Invalid mode. Choose 'pretty' or 'jsonl'")