@Incubating
public class CsvSlurper
extends Object
Represents a CSV parser.
Usage:
def csv = new groovy.csv.CsvSlurper().parseText('name,age\nAlice,30\nBob,25')
assert csv[0].name == 'Alice'
assert csv[1].age == '25'
| Constructor and description |
|---|
CsvSlurper() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public List<Map<String, String>> |
parse(Reader reader)Parse CSV from a reader. |
|
public List<Map<String, String>> |
parse(InputStream stream)Parse CSV from an input stream. |
|
public List<Map<String, String>> |
parse(File file)Parse CSV from a file. |
|
public List<Map<String, String>> |
parse(Path path)Parse CSV from a path. |
<T> |
public List<T> |
parseAs(Class<T> type, String csv)Parse CSV into typed objects using Jackson databinding. |
<T> |
public List<T> |
parseAs(Class<T> type, Reader reader)Parse CSV from a reader into typed objects. |
<T> |
public List<T> |
parseAs(Class<T> type, File file)Parse CSV from a file into typed objects. |
<T> |
public List<T> |
parseAs(Class<T> type, Path path)Parse CSV from a path into typed objects. |
|
public List<Map<String, String>> |
parseText(String csv)Parse the content of the specified CSV text. |
|
public CsvSlurper |
setQuoteChar(char quoteChar)Set the quote character (default: double-quote). |
|
public CsvSlurper |
setSeparator(char separator)Set the column separator character (default: comma). |
|
public CsvSlurper |
setUseHeader(boolean useHeader)Set whether the first row is a header row (default: true). |
Parse CSV from a reader.
When useHeader is true (the default), each row is returned as a map keyed
by column headers from the first row. When useHeader is false, maps are
keyed by auto-generated column names.
reader - the reader of CSVParse CSV from an input stream. The caller is responsible for closing the stream.
stream - the input stream of CSVParse CSV from a file.
file - the CSV fileParse CSV from a path.
path - the path to the CSV file Parse CSV into typed objects using Jackson databinding.
Supports @JsonProperty and @JsonFormat annotations for
column mapping and type conversion.
type - the target typecsv - the CSV textT - the target typeParse CSV from a reader into typed objects.
type - the target typereader - the reader of CSVT - the target typeParse CSV from a file into typed objects.
type - the target typefile - the CSV fileT - the target typeParse CSV from a path into typed objects.
type - the target typepath - the path to the CSV fileT - the target typeParse the content of the specified CSV text.
csv - the CSV textSet the quote character (default: double-quote).
quoteChar - the quote characterSet the column separator character (default: comma).
separator - the separator characterSet whether the first row is a header row (default: true).
useHeader - true to treat the first row as headersCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.