Overview
In most cases, you will be using source-to-destination transformation to read data in any Format, transform it, and load it into any destination. There are cases, however, when you want to programmatically transform a string in any Format, for example, JSON or XML, into DataSet.
Also, read how to do the opposite: serialize any data set into the string in the specific Format.
Convert string in any Format into data set using JavaScript
You can use the following code to convert a string in any Format into DataSet using ConnectorUtils#str2DataSet(...).
var dataSet = com.toolsverse.etl.connector.ConnectorUtils.str2DataSet(null,
'fully.qualified.connector.class.name', parameters, encodedStr);
Available connectors
- JSON:
com.toolsverse.etl.connector.json.JsonConnector
- XML:
com.toolsverse.etl.connector.xml.XmlObjectConnector
- CSV:
com.toolsverse.etl.connector.text.TextConnector
Parameters
The parameters are either a key=value;key=value
string or null
, which means that the default values for the parameters will be used.
From JSON
Available parameters
Parameter | Description | Possible values | Default value |
---|---|---|---|
start | The type of the start element |
|
array |
rootname | The name of the named root object | any string | null |
nested | The type of nested elements |
|
array |
forsql | Convert column names to SQL-compatible | false | true | false |
Example
var dataSet = com.toolsverse.etl.connector.ConnectorUtils.str2DataSet(null,
'com.toolsverse.etl.connector.json.JsonConnector',
'start=variable;nested=variable', jsonString);
From XML
Available parameters
Parameter | Description | Possible values | Default value |
---|---|---|---|
rootname | The name of the root element | any string | automatic |
namespace | The namespace | valid namespace | null |
xmlversion | XML version | 1.0 | 1.1 | 1.0 |
rowtag | Tag for repeating elements | Valid XML tag name | automatic |
parseattrs | Parse XML attributes | false | true | false |
parserootattrs | Parse XML attributes in root node | true | false | true |
parsecdata | Parse values in CDATA tag | true | false | true |
forsql | Convert column names to SQL-compatible | false | true | false |
Example
var dataSet = com.toolsverse.etl.connector.ConnectorUtils.str2DataSet(null,
'com.toolsverse.etl.connector.xml.XmlObjectConnector',
'rootname=products;rowtag=product', xmlString);
From CSV
Available parameters
Parameter | Description | Possible values | Default value |
---|---|---|---|
delimiter | Field delimiter | any valid character | , |
lineseparator | Line separator |
|
s |
charseparator | Enclosure character | any valid character | " |
alwaysquote | Always enclose fields | false | true | false |
escapequote | Escape double-quotes | false | true | false |
forsql | Convert column names to SQL-compatible | false | true | false |
Example
var dataSet = com.toolsverse.etl.connector.ConnectorUtils.str2DataSet(null,
'com.toolsverse.etl.connector.text.TextConnector',
'alwaysquote=true;escapequote=true', csvString);
Comments
0 comments
Please sign in to leave a comment.