CSV Parser extension
A comma-separated values (CSV) file stores tabular data (numbers and text) in plain-text form. With the ThingWorx CSV Parser extension, parse and manipulate CSV files within ThingWorx. This allows you to import CSV data and store it in ThingWorx, or merely treat it as a data store and extract additional value from the CSV data. To use the CSV Parser extension, download and import the CSVParser_Extensions.zip
into ThingWorx.
After importing the extension, a new ThingWorx Resource becomes available, called CSVParserFunctions. This offers services that help dealing with csv files.
It is recommended that import files are UTF-8 encoded.
The CSV Parser extension is available on IQNOX Free ThingWorx Widgets website.
Services
The CSV Parser functionality is located in the services Snippets tab with the following services:
- GetCSVFile: This service parses a CSV file from an HTTP GET (output result is an infotable). It has the following configurable parameters:
header
(Http headers)fieldDelimiter
(field delimiter)ignoreSSLErrors
(Ignore SSL certification errors)columnMappings
(Column maps)hasHeader
(CSV file has a header row)latitudeField
(Latitude field index)password
(URL password)url
(URL)longitudeField
(Longitude field index)username
(URL username)stringDelimiter
(string value delimiter)dateFormat
(Date time format)dataShape
(Data shape)timeout
(Optional timeout in seconds)
- GetOrderedFieldOutput: This service returns a list of data exports (output result is an infotable). It has the following configurable parameters:
orderedFieldList
(the infotable to use as the source)inputInfotable
(an ordered CSV list of the fields to be returned from the input table)
- ParseCSVFile: This service parses a CSV file from text (the output result is an infotable). It has the following configurable parameters:
content
(Content)fieldDelimiter
(Field delimiter)columnMappings
(Column maps)hasHeader
(File has header row)latitudeField
(Latitude field index)longitudeField
(Longitude field index)stringDelimiter
(String value delimiter)dateFormat
(Date time format)dataShape
(Data shape)
- ReadCSVFile: This service parses a CSV file from a repository (the output result is an infotable). It has the following configurable parameters:
path
(Path to file)fieldDelimiter
(Field delimiter)columnMappings
(Column maps)hasHeader
(File has a header row)latitudeField
(Latitude field index)longitudeField
(Longitude field index)stringDelimiter
(String value delimiter)dateFormat
(Date time format)dataShape
(Data shape)
- WriteCSVFile: This service writes a CSV file to a repository. It has the following configurable parameters:
data
(Infotable data)path
(Path to file)fileRepository
(File repository name)withHeader
(Use headers for column names)
Read CSV service
// result: INFOTABLE
var result = Resources.CSVParserFunctions.ReadCSVFile({
path: "/path/to/file.csv" /* STRING */,
columnMappings: undefined /* STRING */,
hasHeader: undefined /* BOOLEAN */,
longitudeField: undefined /* NUMBER */,
dateFormat: undefined /* STRING */,
fileRepository: "SystemRepository" /* THINGNAME */,
latitudeField: undefined /* NUMBER */,
fieldDelimiter: undefined /* STRING */,
stringDelimiter: undefined /* STRING */,
dataShape: "MyDataShape" /* DATASHAPENAME */
});
Write CSV service
var result = DataShapes.MyDataShape.CreateValues();
var newRow = {
firstField: "FirstFieldValue",
secondField: "SecondFieldValue",
};
result.AddRow(newRow);
// no return
var result = Resources["CSVParserFunctions"].WriteCSVFile({
path: "/path/to/file.csv" /* STRING */,
data: result /* INFOTABLE */,
fileRepository: "SystemRepository" /* THINGNAME */,
withHeader: undefined /* BOOLEAN */
});
Note that the WriteCSVFile
will be affected by the value of the following localization tokens for the user executing the service:
csvFieldDelimiter
: controls which delimiter is used between fieldscsvDecimalDelimiter
: controls the delimiter for number decimals
This means that the export can be customized on a per user basis. Additionally, these settings will also affect the Data Export mashup widget.