For Dashboard Designers Reference CSVParser
Friday, November 11, 2022 12:54 PMCSVParser
Label: :IA_Function
Property: type: CsvParser
Inherits from: Function
Parse a delimited data string or remote url and converts to JSON output.
Parameters
Key | Description | Default value | Possible values |
---|---|---|---|
csv |
String of delimited text to be parsed | string | |
options |
Optional config object | object of parameter-value pairs |
CONFIG OPTIONS
Option | Explanation |
---|---|
delimiter | The delimiting character. Leave blank to auto-detect from a list of most common delimiters, or any values passed in through delimitersToGuess. It can be a string or a function. If string, it must be one of length 1. If a function, it must accept the input as first parameter and it must return a string which will be used as delimiter. In both cases it cannot be found in Papa.BAD_DELIMITERS. |
newline | The newline sequence. Leave blank to auto-detect. Must be one of \r , \n , or \r\n . |
quoteChar | The character used to quote fields. The quoting of all fields is not mandatory. Any field which is not quoted will correctly read. |
escapeChar | The character used to escape the quote character within a field. If not set, this option will default to the value of quoteChar, meaning that the default escaping of quote character within a quoted field is using the quote character two times. (e.g. "column with ""quotes"" in text") |
header | If true, the first row of parsed data will be interpreted as field names. An array of field names will be returned in meta, and each row of data will be an object of values keyed by field name instead of a simple array. Rows with a different number of fields from the header row will produce an error. Warning: Duplicate field names will overwrite values in previous fields having the same name. |
dynamicTyping | If true, numeric and boolean data will be converted to their type instead of remaining strings. Numeric data must conform to the definition of a decimal literal. Numerical values greater than 2^53 or less than -2^53 will not be converted to numbers to preserve precision. European-formatted numbers must have commas and dots swapped. If also accepts an object or a function. If object it's values should be a boolean to indicate if dynamic typing should be applied for each column number (or header name if using headers). If it's a function, it should return a boolean value for each field number (or name if using headers) which will be passed as first argument. |
preview | If > 0, only that many rows will be parsed. |
comments | A string that indicates a comment (for example, "#" or "//"). When Papa encounters a line starting with this string, it will skip the line. |
download | If true, this indicates that the string you passed as the first argument to parse() is actually a URL from which to download a file and parse its contents. |
downloadRequestHeaders | If defined, should be an object that describes the headers. |
skipEmptyLines | If true, lines that are completely empty (those which evaluate to an empty string) will be skipped. If set to 'greedy', lines that don't have any content (those which have only whitespace after parsing) will also be skipped. |
fastMode | Fast mode speeds up parsing significantly for large inputs. However, it only works when the input has no quoted fields. Fast mode will automatically be enabled if no " characters appear in the input. You can force fast mode either way by setting it to true or false. |
beforeFirstChunk | A function to execute before parsing the first chunk. Can be used with chunk or step streaming modes. The function receives as an argument the chunk about to be parsed, and it may return a modified chunk to parse. This is useful for stripping header lines (as long as the header fits in a single chunk). |
transform | A function to apply on each value. The function receives the value as its first argument and the column number or header name when enabled as its second argument. The return value of the function will replace the value it received. The transform function is applied before dynamicTyping. |
delimitersToGuess | An array of delimiters to guess from if the delimiter option is not set. |
Outgoing triggers
Type: success
Occurrence: Fires when the given delimited data was read and parsed successfully.
Additional event properties (besides the inherited properties):
Key | Description | Possible values |
---|---|---|
data |
If option header is false, rows are arrays; otherwise they are objects of data keyed by the field name. | array |
errors |
Array of errors. | array |
meta |
Extra information about the parse, such as delimiter used, the newline sequence, whether the process was aborted, etc. | object |