Hi Nora,
which version of TWX are you using?
For the HTTP Rest Post service I assume that this is a service from another system (not ThingWorx) and you try to send ThingWorx data to this service, right? Can you share some info about the target service?
Do you try to send this InfoTable content from within a ThingWorx service? If so: Can you share the corresponding snippet? If not: how do you access the output of "var table = ThingTemplates["myTemplate"].QueryImplementingThingsWithData();"?
In general you could try 3 things to get JSON from an InfoTable:
- table.ToJSON() function (Pai already mentioned it - and I remeber that it was already available in 5.x when I started with TWX)
- JSON.stringify( myJSObject ) is a general purpose Javascript function that allows to convert javascript objects in JSON. Give it a try for the table as a whole or for your rows if then table doesn't work. I used that quite often when I wanted to output more complex object types in log messages. Check the official documentation that I linked to: the stringify() method can take more arguments so that you can tweak the output if needed.
- I'd also try the .toString() method on the table, row and row[field] objects.
Furthermore the snippet for iterating over infotable row fields is ("Iterate infotable datashape fields" from the Snippets section for Infotable):
// infotable datashape iteration
var dataShapeFields = yourInfotableHere.dataShape.fields;
for (var fieldName in dataShapeFields) {
//logger.warn('field name is ' + dataShapeFields[fieldName].name);
//logger.warn('field basetype is ' + dataShapeFields[fieldName].baseType);
}
It is not for each(field in row) that you use above. for each ... in is in general a bit problematic - see the official documentation that I linked to. And it doesn't help you here as you won't get the row property names with for each...in, rather use for...in.