CSV Decode | DECODE_CSV

Syntax

DECODE_CSV( [value], [delimiter = ","], [rowDelimiter = null], [parseCSVAsArray = false] )

Parameters

value
A CSV encoded TEXT value to decode. If it is not a TEXT value, it will be converted to one with the STRING operation.

delimiter optional
The TEXT value that is the separator for the values within a row of the CSV. In a typical CSV, this value is a comma (,) character, and is the default. If the value is not a TEXT value, the argument will be ignored and the default used.

rowDelimiter optional
The TEXT value that is the separator for the rows of the CSV. In a typical CSV, this value is either a carriage-return new-line sequence ('\r\n') or just a new-line character ('\n') which is auto-detected if this value is not provided. Unless, PARSE CSV AS ARRAY is TRUE, the first row of the CSV will be treated as a header row which will determine the keys of the resulting MAP object for each row. If the value is not a TEXT value, the argument will be ignored and the default will be used.

parseCSVAsArray optional
If TRUE, an ARRAY of ARRAY entries will be returned rather than an ARRAY of OBJECT / MAP values.

Return Value

An ARRAY of OBJECT / MAP entries or an ARRAY of ARRAYS if PARSE CSV AS ARRAY is TRUE. If VALUE is not a valid CSV encoded TEXT value, NULL will be returned.

Description

Decode a TEXT value as a CSV.

Examples

# VALUE is 
# "ID,Name,Species
# 1,Amy,Alligator
# 2,Barry,Beluga
# 3,Cindy,Snake
# 4,David,Duck"
DECODE_CSV(VALUE)
# returns [
#   ["ID" => "1", "Name" => "Amy", "Species" => "Alligator"],
#   ["ID" => "2", "Name" => "Barry", "Species" => "Beluga"],
#   ["ID" => "3", "Name" => "Cindy", "Species" => "Snake"],
#   ["ID" => "4", "Name" => "David", "Species" => "Duck"]
# ]
Parse a pipe-delimited TEXT value
# VALUE is 
# "ID|Name|Species
# 1|Amy|Alligator
# 2|Barry|Beluga
# 3|Cindy|Snake
# 4|David|Duck"
DECODE_CSV(VALUE, "|")
# returns [
#   ["ID" => "1", "Name" => "Amy", "Species" => "Alligator"],
#   ["ID" => "2", "Name" => "Barry", "Species" => "Beluga"],
#   ["ID" => "3", "Name" => "Cindy", "Species" => "Snake"],
#   ["ID" => "4", "Name" => "David", "Species" => "Duck"]
# ]
Parse the CSV as an array (useful when the content has no initial header row)
# VALUE is 
# 1,Amy,Alligator
# 2,Barry,Beluga
# 3,Cindy,Snake
# 4,David,Duck"
DECODE_CSV(VALUE, null, null, true)
# returns [
#   ["1", "Amy", "Alligator"],
#   ["2", "Barry", "Beluga"],
#   ["3", "Cindy", "Snake"],
#   ["4", "David", "Duck"]
# ]