File size: 1,063 Bytes
c0670d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
# 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'")