Skip to main content
15-Moonstone
June 3, 2020
Solved

Infotable to Json gives datashape information

  • June 3, 2020
  • 1 reply
  • 2850 views

Hello,

I am using the below code to convert the infotable to JSON. But i see that the JSON also contains the datashape information which i dont need. How can i get ride of this datashape information in the JSON output.

var params = {
table: outPutInfo /* INFOTABLE */
};
var result = Resources["InfoTableFunctions"].ToJSON(params);

 

Thanks

Best answer by CarlesColl

I would do something like this:

 

var params = {
table: outPutInfo /* INFOTABLE */
};
var result = Resources["InfoTableFunctions"].ToJSON(params);

result.array = result.rows;
delete result.rows;
delete result.dataShape;

 The reason to rename rows to array it's to conform to ThingWorx handling of JSON and infotables, if it sees a rows property it expects a dataShape otherwise it can crash or get stuck, if you convert it to a ThingWorx raw JSON array which requieres the naming convention "array" you are good to go.

 

Regards.

1 reply

1-Visitor
June 4, 2020

I would do something like this:

 

var params = {
table: outPutInfo /* INFOTABLE */
};
var result = Resources["InfoTableFunctions"].ToJSON(params);

result.array = result.rows;
delete result.rows;
delete result.dataShape;

 The reason to rename rows to array it's to conform to ThingWorx handling of JSON and infotables, if it sees a rows property it expects a dataShape otherwise it can crash or get stuck, if you convert it to a ThingWorx raw JSON array which requieres the naming convention "array" you are good to go.

 

Regards.

sbt15-MoonstoneAuthor
15-Moonstone
June 4, 2020

Hello Carles,

Thats good information about handling Infotable and JSON in thingworx.

 

In my case I have infotable which contains infotable and that contains infotable, so its like 3 level and may change to more than 3. So in that case should i loop through the depth ?? or what is the efficient way to achieve the same.

 

Thanks you!

1-Visitor
June 4, 2020

Yep for sure you will have to do three inner loops.