code-docs/plugins/plugins/csv.md
CSV parsing utilities for Lowdefy.
Provides operators for CSV parsing and generation.
| Operator | Purpose |
|---|---|
_csv_parse | Parse CSV string to array |
_csv_stringify | Convert array to CSV string |
Parse CSV string to array of objects:
data:
_csv_parse:
csv:
_state: csvInput
options:
header: true # First row is headers
skipEmptyLines: true
delimiter: ','
| Option | Type | Description |
|---|---|---|
header | boolean | Use first row as headers |
skipEmptyLines | boolean | Skip empty lines |
delimiter | string | Field delimiter (default: ,) |
columns | array | Specify column names |
With header: true:
[
{ name: 'John', email: '[email protected]' },
{ name: 'Jane', email: '[email protected]' },
];
Without header:
[
['name', 'email'],
['John', '[email protected]'],
['Jane', '[email protected]'],
];
Convert array to CSV:
csvOutput:
_csv_stringify:
data:
_request: getData
options:
header: true
columns:
- key: name
header: Name
- key: email
header: Email Address
| Option | Type | Description |
|---|---|---|
header | boolean | Include header row |
columns | array | Column definitions |
delimiter | string | Field delimiter |
events:
onFileUpload:
- id: parse
type: SetState
params:
importedData:
_csv_parse:
csv:
_event: content
options:
header: true
events:
onExport:
- id: generate
type: SetState
params:
csvDownload:
_csv_stringify:
data:
_request: getExportData
options:
header: true
Combine with Fetch action for download:
events:
onClick:
- id: downloadCsv
type: Fetch
params:
url:
_string:
- 'data:text/csv;charset=utf-8,'
- _csv_stringify:
data:
_request: getData
download: export.csv