File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
1111 */
1212import { 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.
1621let text = `
1722url,views,likes
1823https://deno.land,10,7
You can’t perform that action at this time.
0 commit comments