I am trying to iterate through a JSON and map it to info table (later show the data calculated in a mashup).
Based on this article: How to convert JSON to an InfoTable in ThingWorx
Thingworx Versions in use are 8.4 and 8.5.
var params = {
url: "https://<URL to JSON>" /* STRING */,
};
// result: JSON
var jsonData = Resources["ContentLoaderFunctions"].GetJSON(params);
// Function gives back a string-> toJSON only works with Infotable
jsonData = jsonData.ToJSON();
// lenght is only possible with actual JSON Object
logger.warn(jsonData.items.length);
var result = jsonData;
// TO DO create Infotable and change result to Info Table
/*
var dparams = {
infoTableName : "InfoTable",
dataShapeName : "LiveData"
};
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(AlertEvent)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(dparams);
*/
My major question is what does the GETJSON function give back?
My goal is to iterate through the JSON and create an InfoTable for later displaying KPIs in a Dashboard.
Live Data from the Datasource
Solved! Go to Solution.
Resources["ContentLoaderFunctions"].GetJSON returns a JSON-Object so you don't need to convert it with ToJSON(). You can use this JSON-object like every other JSON-object. You can iterate through JSON as well as iterate through a info table.
I think it makes sense to see what your JSON object looks like:
logger.debug("jsonData: " + JSON.stringify(jsonData))
Resources["ContentLoaderFunctions"].GetJSON returns a JSON-Object so you don't need to convert it with ToJSON(). You can use this JSON-object like every other JSON-object. You can iterate through JSON as well as iterate through a info table.
I think it makes sense to see what your JSON object looks like:
logger.debug("jsonData: " + JSON.stringify(jsonData))