Format Converter
The Format Converter operator converts blobs between CSV, JSON and XML. The output format is set as a configuration value. The input format is deduced using the following rules:
-
If it starts with { or [, it must be JSON.
-
If it starts with <, it must be XML.
-
Otherwise, it must be CSV.
If the first field in CSV input starts with any of the three special characters ({, [ and <), it must be quoted.
CSV
-
any valid UTF-8 character or escape sequence may be used as field separator ("comma").
-
output CSV will use CRLF as a record separator, placing it after every record including the last one.
-
input CSV can use either LF or CRLF as a record separator, and the last record may or may not be followed by a separator.
-
since CSV lacks any type information, when converting to JSON, all fields will be made into strings.
XML
-
xmlOutputRootTag is not empty, in which case all input content will be placed within this tag. For example, input
[{"a": 1}, {"b": "hello"}]
becomes<root> <item> <a>1</a> </item> <item> <b>hello</b> </item> </root>
where xmlOutputRootTag is root and xmlOutputItemTag is item. - Input is a JSON object containing a single property, whose key will be used
as root tag. For example:
{"countries": [{"id": "US", "currency": "USD"}, {"id": "DE", "currency": "EUR"}]}
becomes<countries> <country> <id>US</id> <currency>USD</currency> </country> <country> <id>DE</id> <currency>EUR</currency> </country> </countries>
assuming xmlOutputRootTag is empty and xmlOutputItemTag is country.
<people> <person> <name>Bonnie</name> <age>23</age> </person> <person> <name>Clyde</name> <age>25</age> </person> </people>will be turned into
{ "people": { "person": [ {"name": "Bonnie", "age": "23"}, {"name": "Clyde", "age": "25"} ] } }Notice that all textual values in XML become JSON strings.
Configuration Parameters
Parameter |
Type |
Description |
---|---|---|
csvComma
|
string |
The field separator.
Default: "," |
targetFormat |
string | The file type to be converted to. Accepted values are JSON, CSV
or XML.
Default: "JSON" |
csvHeaderIncluded |
bool |
Indicates whether or not each CSV input will have a header as
first line. If the header will not be present, the fields parameter
must be supplied.
Default: false |
fields |
string |
A comma-separated list of field names. This value is only
required when:
Default: "" |
xmlOutputRootTag |
string |
The name for the root tag to be used when converting to XML. If this value is empty, the operator will only be able to convert JSON input, which must be an object with a single property that will serve as root tag. Default: "items" |
xmlOutputItemTag |
string |
The tag name to be used for each element in an array when converting to XML. If this value is empty, xmlOutputRootTag will be used. Default: "item" |
Input
Input |
Type |
Description |
---|---|---|
input |
blob |
The source data to be converted. |
Output
Output |
Type |
Description |
---|---|---|
output |
blob |
The resulting data, in targetFormat format. |