Fluent API
Fluent API methods for CSVFile class in BoxLang Plus
The CSVFile class provides a fluent, chainable API for all CSV operations.
Static Constructors
CSVFile.empty()
CSVFile.empty()Creates an empty CSVFile instance
Returns: CSVFile object
CSVFile.fromJson( jsonString )
CSVFile.fromJson( jsonString )Creates CSVFile from JSON array of objects
Parameters:
jsonString(string) - JSON arrayReturns: CSVFile object
Example:
CSVFile.fromJson('[{"name":"John","age":30}]')
CSVFile.fromArray( arrayOfStructs )
CSVFile.fromArray( arrayOfStructs )Creates CSVFile from array of structs
Parameters:
arrayOfStructs(array) - Array of structsReturns: CSVFile object
CSVFile.fromQuery( query )
CSVFile.fromQuery( query )Creates CSVFile from BoxLang Query
Parameters:
query(Query) - Query objectReturns: CSVFile object
File I/O Methods
load( path )
load( path )Loads CSV file from specified path
Parameters:
path(string) - File pathReturns: this (for chaining)
Example:
csv.load("data.csv")
loadFromString( csvContent )
loadFromString( csvContent )Loads CSV data from a string
Parameters:
csvContent(string) - CSV contentReturns: this (for chaining)
loadFromJson( jsonString )
loadFromJson( jsonString )Loads CSV data from JSON string
Parameters:
jsonString(string) - JSON arrayReturns: this (for chaining)
loadFromQuery( query )
loadFromQuery( query )Loads CSV data from Query object
Parameters:
query(Query) - Query objectReturns: this (for chaining)
loadFromArray( arrayOfStructs )
loadFromArray( arrayOfStructs )Loads CSV data from array of structs
Parameters:
arrayOfStructs(array) - Array of structsReturns: this (for chaining)
save( path, [overwrite] )
save( path, [overwrite] )Saves CSV file to specified path
Parameters:
path(string) - File pathoverwrite(optional, boolean) - Whether to overwrite existing file
Returns: this (for chaining)
Example:
csv.save("output.csv", true)
save()
save()Saves CSV file using previously set path
Returns: this (for chaining)
Configuration Methods
delimiter( char )
delimiter( char )Sets delimiter character
Parameters:
char(character) - Delimiter (e.g., ',', '|', '\t')Returns: this (for chaining)
Example:
csv.delimiter('|')
quote( char )
quote( char )Sets quote character
Parameters:
char(character) - Quote character (default: '"')Returns: this (for chaining)
escape( char )
escape( char )Sets escape character
Parameters:
char(character) - Escape character (default: '"')Returns: this (for chaining)
lineSeparator( string )
lineSeparator( string )Sets line separator string
Parameters:
string(string) - Line separator (e.g., "\n", "\r\n")Returns: this (for chaining)
trim( boolean )
trim( boolean )Sets whether to trim whitespace from values
Parameters:
boolean(boolean) - Enable/disable trimmingReturns: this (for chaining)
headers( boolean )
headers( boolean )Sets whether CSV has headers in first row
Parameters:
boolean(boolean) - Enable/disable headersReturns: this (for chaining)
skipHeaderRecord( boolean )
skipHeaderRecord( boolean )Sets whether to skip header record when parsing
Parameters:
boolean(boolean) - Enable/disable skippingReturns: this (for chaining)
allowMissingColumnNames( boolean )
allowMissingColumnNames( boolean )Sets whether to allow missing column names
Parameters:
boolean(boolean) - Enable/disableReturns: this (for chaining)
ignoreEmptyLines( boolean )
ignoreEmptyLines( boolean )Sets whether to ignore empty lines
Parameters:
boolean(boolean) - Enable/disableReturns: this (for chaining)
nullString( string )
nullString( string )Sets string representation for null values
Parameters:
string(string) - Null representation (e.g., "NULL", "N/A")Returns: this (for chaining)
commentMarker( char )
commentMarker( char )Sets comment marker character
Parameters:
char(character) - Comment marker (e.g., '#')Returns: this (for chaining)
ignoreSurroundingSpaces( boolean )
ignoreSurroundingSpaces( boolean )Sets whether to ignore spaces around values
Parameters:
boolean(boolean) - Enable/disableReturns: this (for chaining)
quoteMode( string )
quoteMode( string )Sets quote mode for writing
Parameters:
string(string) - Quote mode: "ALL", "MINIMAL", "NON_NUMERIC", "NONE", "ALL_NON_NULL"Returns: this (for chaining)
Example:
csv.quoteMode("ALL")
quoteMode( quoteModeEnum )
quoteMode( quoteModeEnum )Sets quote mode for writing using QuoteMode enum
Parameters:
quoteModeEnum(QuoteMode) - QuoteMode enum valueReturns: this (for chaining)
Note: This is primarily for Java interoperability
allowDuplicateHeaderNames( boolean )
allowDuplicateHeaderNames( boolean )Sets whether to allow duplicate column names
Parameters:
boolean(boolean) - Enable/disableReturns: this (for chaining)
autoFlush( boolean )
autoFlush( boolean )Sets whether to flush after each record write
Parameters:
boolean(boolean) - Enable/disableReturns: this (for chaining)
trailingDelimiter( boolean )
trailingDelimiter( boolean )Sets whether to add trailing delimiter at end of records
Parameters:
boolean(boolean) - Enable/disableReturns: this (for chaining)
headerComments( ...comments )
headerComments( ...comments )Sets header comments to write before CSV data
Parameters:
comments(string...) - Variable arguments of comment stringsReturns: this (for chaining)
Example:
csv.headerComments("File created on " & now(), "Author: System")
headerComments( commentsArray )
headerComments( commentsArray )Sets header comments to write before CSV data
Parameters:
commentsArray(array) - Array of comment stringsReturns: this (for chaining)
Example:
csv.headerComments(["File created on " & now(), "Author: System"])
overwrite( boolean )
overwrite( boolean )Sets whether to overwrite existing files when saving
Parameters:
boolean(boolean) - Enable/disable overwritingReturns: this (for chaining)
setPath( path )
setPath( path )Sets file path for future operations
Parameters:
path(string) - File pathReturns: this (for chaining)
Data Manipulation Methods
setHeaders( ...headers )
setHeaders( ...headers )Sets header columns for the CSV
Parameters:
headers(string...) - Variable arguments of header namesReturns: this (for chaining)
Example:
csv.setHeaders("Name", "Email", "Age")
setHeaders( headersArray )
setHeaders( headersArray )Sets header columns for the CSV
Parameters:
headersArray(array) - Array of header namesReturns: this (for chaining)
Example:
csv.setHeaders(["Name", "Email", "Age"])
setRowData( rowNumber, rowData )
setRowData( rowNumber, rowData )Sets data for a specific row (1-based indexing)
Parameters:
rowNumber(number) - Row number (1-based)rowData(array) - Array of values for the row
Returns: this (for chaining)
Example:
csv.setRowData(1, ["A", "B", "C"])
addRow( rowData )
addRow( rowData )Adds a new row to the CSV
Parameters:
rowData(array) - Array of values for the rowReturns: this (for chaining)
Example:
csv.addRow(["John", "[email protected]", 30])
getRowData( rowNumber )
getRowData( rowNumber )Gets data for a specific row (1-based indexing)
Parameters:
rowNumber(number) - Row number (1-based)Returns: Array of values
getRowCount()
getRowCount()Gets the number of rows in the CSV
Returns: Number of rows
getColumnCount()
getColumnCount()Gets the number of columns in the CSV
Returns: Number of columns
getHeaders()
getHeaders()Gets the header columns
Returns: Array of header names, or null if no headers
clear()
clear()Clears all data from the CSV
Returns: this (for chaining)
Filtering and Mapping Methods
filter( predicate )
filter( predicate )Sets a filter predicate to apply when loading CSV data
Parameters:
predicate(function) - Function that receives a row array and returns booleanReturns: this (for chaining)
Example:
csv.filter((row) => row[2] >= 18)
map( mapper )
map( mapper )Sets a mapper function to transform rows when loading CSV data
Parameters:
mapper(function) - Function that receives and returns a row arrayReturns: this (for chaining)
Example:
csv.map((row) => { row[0] = row[0].toUpperCase(); return row; })
Streaming Methods
process( path, consumer )
process( path, consumer )Streams through CSV file row-by-row without loading into memory
Parameters:
path(string) - Path to CSV fileconsumer(function) - Function that receives each row array
Returns: this (for chaining)
Example:
csv.process("large.csv", (row) => println(row[0]))
process( consumer )
process( consumer )Streams through CSV file using previously set path
Parameters:
consumer(function) - Function that receives each row arrayReturns: this (for chaining)
Export Methods
toArray()
toArray()Converts CSV data to array of arrays
Returns: Array
toJson( [pretty] )
toJson( [pretty] )Converts CSV data to JSON string
Parameters:
pretty(optional, boolean) - Pretty-print JSON (default: false)Returns: JSON string
toQuery()
toQuery()Converts CSV data to BoxLang Query object
Returns: Query object with VARCHAR columns
toString()
toString()Converts CSV data to string representation
Returns: CSV string
Information Methods
getPath()
getPath()Gets the current file path
Returns: File path string or null
getDelimiter()
getDelimiter()Gets the current delimiter character
Returns: Character
hasHeaders()
hasHeaders()Gets whether the CSV has headers
Returns: Boolean
getData()
getData()Gets the raw CSV data as list of string arrays
Returns: List of string arrays
Last updated
Was this helpful?
