Files
AI-upflux-docprocessor/scripts/tojson.py
2026-01-20 13:48:13 -03:00

30 lines
830 B
Python

import pandas as pd
import json
from pathlib import Path
# Configuration
CSV_FILE = "guias.csv"
OUTPUT_DIR = "json_output"
ENCODING = "utf-8"
# Create output directory
Path(OUTPUT_DIR).mkdir(exist_ok=True)
# Read CSV
df = pd.read_csv(CSV_FILE, encoding=ENCODING)
# Convert each row to JSON, skipping row 2 (index 1)
for index, row in df.iterrows():
# Skip the second row (index 1)
if index == 0:
print(f"⊗ Skipped row {index + 1}")
continue
# Save to individual JSON file
output_file = f"{OUTPUT_DIR}/row_{index + 1}.json"
with open(output_file, 'w', encoding=ENCODING) as json_file:
json.dump(row.to_dict(), json_file, indent=2, ensure_ascii=False)
print(f"✓ Created {output_file}")
print(f"\nDone! Created {len(df) - 1} JSON files in '{OUTPUT_DIR}/' directory")