-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv-to-json.js
More file actions
41 lines (33 loc) · 1.24 KB
/
csv-to-json.js
File metadata and controls
41 lines (33 loc) · 1.24 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 data to JSON using DocForge API
// Usage: node csv-to-json.js
const csv = `name,email,role,department,salary
Alice Chen,alice@example.com,Senior Engineer,Engineering,145000
Bob Johnson,bob@example.com,Product Manager,Product,130000
Carol Williams,carol@example.com,Designer,Design,120000
Dave Brown,dave@example.com,Data Scientist,Engineering,140000
Eve Davis,eve@example.com,Marketing Lead,Marketing,115000`;
async function convert() {
const res = await fetch('https://docforge-api.vercel.app/api/csv-to-json', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ csv })
});
if (!res.ok) {
console.error(`Error: ${res.status}`);
process.exit(1);
}
const { data, meta } = await res.json();
console.log('=== Metadata ===');
console.log(`Rows: ${meta.rowCount}`);
console.log(`Columns: ${meta.headers.join(', ')}`);
console.log();
console.log('=== JSON Output ===');
console.log(JSON.stringify(data, null, 2));
// Example: filter and transform
console.log();
console.log('=== Engineering Team (salary > $130k) ===');
const engineers = data
.filter(r => r.department === 'Engineering' && parseFloat(r.salary) > 130000);
console.log(engineers);
}
convert();