Skip to content

Commit 48c5ef0

Browse files
bartlomiejuclaude
andauthored
docs: add file reading example to CSV parsing page (#3032)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d3b1041 commit 48c5ef0

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

examples/scripts/parsing_serializing_csv.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @title Parsing and serializing CSV
33
* @difficulty beginner
44
* @tags cli, deploy, web
5-
* @run <url>
5+
* @run -R <url>
66
* @resource {/examples/import_export} Example: Importing & Exporting
77
* @resource {https://datatracker.ietf.org/doc/html/rfc4180} Spec: CSV
88
* @group Encoding
@@ -11,8 +11,13 @@
1111
*/
1212
import { parse, stringify } from "jsr:@std/csv";
1313

14-
// To parse a CSV string, you can use the the standard library's CSV
15-
// parse function. The value is returned as a JavaScript object.
14+
// To parse a CSV file, read its contents and pass them to the parse function.
15+
const fileContent = await Deno.readTextFile("data.csv");
16+
const fileData = parse(fileContent, { skipFirstRow: true, strip: true });
17+
console.log(fileData);
18+
19+
// You can also parse CSV strings directly. The value is returned as an
20+
// array of objects when skipFirstRow is true.
1621
let text = `
1722
url,views,likes
1823
https://deno.land,10,7

0 commit comments

Comments
 (0)