cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

GetJSON from external source and map it to a info table

otluk
12-Amethyst

GetJSON from external source and map it to a info table

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

1 ACCEPTED SOLUTION

Accepted Solutions
drichter
14-Alexandrite
(To:otluk)

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))

View solution in original post

1 REPLY 1
drichter
14-Alexandrite
(To:otluk)

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))

Top Tags