Customize field mapping in cloud product data sources by writing scripts to parse the data. The IoT Platform allows for script configuration using JavaScript (ECMAScript 5). This topic provides templates and examples for creating custom scripts.
Script template
// Below is a script template to guide your script writing process
/**
* Function name must be parse_line
* Input parameter: line - row data, such as a,b,c
* Output parameter: jsonObj - a JSON object, which should not be empty
*/
function parse_line(line) {
var lines = line.split(",");
return {"a":lines[0],"b":lines[1],"c":lines[2]};
}
Here, a, b, and c denote the field names within the row data.
Script example
// Example data
/*
Input line row data:
32,60
Output JSON:
{
"temperature":32,
"humidity":60
}
*/
function parse_line(line) {
var lines = line.split(",");
return {"temperature":lines[0],"humidity":lines[1]};
}