-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_to_json.py
More file actions
41 lines (30 loc) · 1.18 KB
/
csv_to_json.py
File metadata and controls
41 lines (30 loc) · 1.18 KB
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
31
32
33
34
35
36
37
38
39
40
41
"""
Convert CSV to JSON using DocForge API.
Usage: python csv_to_json.py
"""
import requests
import json
API_URL = "https://docforge-api.vercel.app/api/csv-to-json"
csv_data = """name,email,role,department,start_date
Alice Chen,alice@example.com,Senior Engineer,Engineering,2023-01-15
Bob Johnson,bob@example.com,Product Manager,Product,2022-06-01
Carol Williams,carol@example.com,Designer,Design,2023-03-20
Dave Brown,dave@example.com,Data Scientist,Engineering,2022-11-08
Eve Davis,eve@example.com,Marketing Lead,Marketing,2023-07-12"""
def convert():
response = requests.post(API_URL, json={"csv": csv_data})
if response.status_code != 200:
print(f"Error: {response.status_code}")
return
result = response.json()
print(f"Rows: {result['meta']['rowCount']}")
print(f"Columns: {', '.join(result['meta']['headers'])}")
print()
print(json.dumps(result["data"], indent=2))
# Filter example
engineers = [r for r in result["data"] if r["department"] == "Engineering"]
print(f"\nEngineering team ({len(engineers)} people):")
for eng in engineers:
print(f" - {eng['name']} ({eng['role']})")
if __name__ == "__main__":
convert()