parse
($csv as string) as object()*
Parses a CSV (comma-separated values) string using the default options. |
parse
($csv as string, $options as object()) as object()* external
Parses a CSV (comma-separated values) string using the given options. |
serialize
($obj as object()*) as string*
Serializes a sequence of JSON objects as CSV (comma-separated values) using the default options. |
serialize
($obj as object()*, $options as object()) as string* external
Serializes a sequence of JSON objects as CSV (comma-separated values) using the given options. |
declare function csv:parse($csv as string) as object()*
Quoted values are always considered strings;
unquoted values are attempted to be cast to other types, e.g., integer
(unless the cast-unquoted-values
option is false
).
Casting is attempted in the following order:
integer, decimal, double, and boolean.
If casting fails, the value is considered a string.
Header field names are always considered strings even if unquoted.
In addition to the "normal" values of
true
and false
for boolean,
T
and Y
are also considered "true"
and F
and N
are also considered "false."
The default options are:
cast-unquoted-values
true
.
extra-name
csv:EXTRA_VALUE
is raised).
field-names
missing-value
"null"
.
A "missing" value is one of:
quote-char
characters.quote-char
character as either the first
or last character on a line.null
.
quote-char
"
(U+0022).
quote-escape
quote-char
;
default: same as quote-char
.
This means that an escaped quote is doubled as ""
.
separator
,
(U+002C).
declare function csv:parse($csv as string, $options as object()) as object()* external
Quoted values are always considered strings;
unquoted values are attempted to be cast to other types, e.g., integer
(unless the cast-unquoted-values
option is false
).
Casting is attempted in the following order:
integer, decimal, double, and boolean.
If casting fails, the value is considered a string.
Header field names are always considered strings even if unquoted.
In addition to the "normal" values of
true
and false
for boolean,
T
and Y
are also considered "true"
and F
and N
are also considered "false."
cast-unquoted-values
true
. extra-name
csv:EXTRA_VALUE
is raised). If this option is given and a line contains one or more extra values (that is, values that have no corresponding field names), then the extra values are assigned as the values for fields having extra-name
as their names. If extra-name
contains a #
(U+0023), then the #
is substituted with the field number (where field numbers start at 1). If extra-name
does not contains a #
, then the field number is appended.
field-names
missing-value
"null"
. A "missing" value is one of: separator
characters.separator
character as either the first or last character on a line."error"
csv:MISSING_VALUE
is raised."omit"
"null"
null
.quote-char
"
(U+0022). quote-escape
quote-char
; default: same as quote-char
. If quote-escape
equals quote-char
, it means that quote-char
must be doubled to escape it. If quote-escape
does not equal quote-char
, it means that quote-escape
is used to escape quote-char
. For example, a quote-char
of "
(U+0022) and a quote-escape
of \
(U+005C) means that quotes will be escaped by \"
. separator
,
(U+002C). declare function csv:serialize($obj as object()*) as string*
field-names
serialize-boolean-as
true
and false
as;
default: true
and false
.
serialize-header
true
.
The first string result is the header line
comprised of all the objects' keys' names.
serialize-null-as
null
values as;
default: null
.
quote-char
"
(U+0022).
quote-escape
quote-char
;
default: same as quote-char
.
This means that quote-char
is doubled to escape it.
separator
,
(U+002C).
declare function csv:serialize($obj as object()*, $options as object()) as string* external
field-names
serialize-boolean-as
true
and false
as; default: true
and false
. This must be a sub-object with the two keys "true"
and "false"
, e.g.: { "true" : "Y", "false" : "N" }
. serialize-header
true
. If true
, the first string result is the header line comprised of all the objects' keys' names; if false
, the heder line is not returned. serialize-null-as
null
values as; default: null
. quote-char
"
(U+0022). quote-escape
quote-char
; default: same as quote-char
. If quote-escape
equals quote-char
, it means that quote-char
must be doubled to escape it. If quote-escape
does not equal quote-char
, it means that quote-escape
is used to escape quote-char
. For example, a quote-char
of "
(U+0022) and a quote-escape
of \
(U+005C) means that quotes will be escaped by \"
. separator
,
(U+002C).