Application Examples for csvParse(csvString, recordSeparator, fieldSeparator, quoteCharacter, containsHeader)

Example 1

You can use the function csvParse(csvString, recordSeparator, fieldSeparator, quoteCharacter, containsHeader) to parse the following CSV character string into an array of structured objects:

Time,Temperature,PressureCRLF
09/14/2021 07:55:56,76.5,1023.34CRLF
09/14/2021 08:55:42,73.0,1024.07CRLF
09/14/2021 09:55:58,71.0,1017.1CRLF

The following conditions should apply:

Function Parameters Description Character Used
recordSeparator Record separator: Carriage return (CR) + line feed (LF) CRLF
fieldSeparator Field separator Comma
quoteCharacter Quotation marks No quotation marks
containsHeader Contains header Yes

Expression used:csvParse('csvString',crlf,",","",true)

Result:

[
	{
		"Time": "09/14/2021 07:55:56",
		"Temperature": "76.5",
		"Pressure": "1023.34"
	},
	{
		"Time": "09/14/2021 08:55:42",
		"Temperature": "73.0",
		"Pressure": "1024.07"
	},
{
		"Time": "09/14/2021 09:55:58",
		"Temperature": "71.0",
		"Pressure": "1017.1"
	}
]

Example 2

In example 2, you want to parse the following CSV string:

"09/14/2021 07:55:56"->"true"->"-12"->"Good"CR
"09/14/2021 07:56:50"->"false"->"0"->"Bad"CR
"09/14/2021 07:57:52"->"true"->"42.07"->"Unknown"

The following conditions should apply:

Function Parameters Description Character Used
recordSeparator Record separator: Carriage return (CR) CR
fieldSeparator Field separator Tab (→)
quoteCharacter Quotation marks Double quotation marks
containsHeader Contains header No

Expression:csvParse('csvString',cr,tab,doublequote,false)

Result:

[
	{
		"0": "09/14/2021 07:55:56",
		"1": "true",
		"2": "-12",
		"3": "Good"
	},
	{
		"0": "09/14/2021 07:56:50",
		"1": "false",
		"2": "0",
		"3": "Bad"
	},
{
		"0": "09/14/2021 07:57:52",
		"1": "true",
		"2": "42.07",
		"3": "Unknown"
	}
]

Example 3

In example 3, you want to parse the following CSV string:

'13, Main Street' '' 'Springfield'CR
'Dietmar-Hopp-Allee 11CRBuilding 1' ''EVZ'' 'Walldorf'CR

The following conditions should apply:

Function Parameters Description Character Used
recordSeparator Record separator: Carriage return (CR) CR
fieldSeparator Field separator Space
quoteCharacter Quotation marks Single quotation marks
containsHeader Contains header No

Expression:csvParse('csvString',cr," ",singlequote,false)

Result:

This leads to an error because the first and second fields of the second record contain the record separator CR and the quotation mark '.