How do I remove datashape field from below JSON output?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
How do I remove datashape field from below JSON output?
{
"data": [
{
"usageId": "50030540014333322800000050",
"assetFound": true,
"compartments": {
"rows": [
{
"compartmentId": "50030540014333322800000052",
"observableProperties": {
"gatewayLocationDescription": "Ireland",
"temperature": 6,
"timestamp": 1612393200000
},
"compartmentUsage": {
"compartmentState": "Inuse",
"minTemperatureThreshold": 2.2
}
},
{
"compartmentId": "50030540014333322800000051",
"observableProperties": {
"gatewayLocationDescription": "Belgium",
"temperature": 2,
"timestamp": 1612220400000
},
"compartmentUsage": {
"compartmentState": "Idle"
}
}
],
"dataShape": {
"fieldDefinitions": {
"compartmentId": {
"name": "compartmentId",
"aspects": {
"isPrimaryKey": false
},
"description": "",
"baseType": "STRING",
"ordinal": 1
},
"observableProperties": {
"name": "observableProperties",
"aspects": {
"isPrimaryKey": false
},
"description": "",
"baseType": "JSON",
"ordinal": 3
},
"compartmentUsage": {
"name": "compartmentUsage",
"aspects": {
"isPrimaryKey": false
},
"description": "",
"baseType": "JSON",
"ordinal": 2
}
}
}
}
}
],
"message": "Information found",
"status": "Success"
}
- Labels:
-
Best Practices
-
Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @KN_9774047
You can refer to below link to get rid of datashape fields coming along in your JSON output:
Remove DataShapes from JSON Output
Do revert for more queries.
Regards,
Sudeepta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Tried that way in Thingworx 9.0.3 but not working out.
datShape field is still showing up in the output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @KN_9774047
I gave the code a try in 9.0.3 and able to get output without datashape. Sharing my script for reference:
var params = {
infoTableName: undefined /* STRING */,
dataShapeName: "DS" /* DATASHAPENAME */
};
// result: INFOTABLE
var result1= Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
var newEntry = new Object();
newEntry.name = "test1"; // STRING - isPrimaryKey = true
newEntry.value = "test 1"; // STRING - isPrimaryKey = true
result1.AddRow(newEntry);
newEntry.name = "test2"; // STRING - isPrimaryKey = true
newEntry.value = "test 2"; // STRING - isPrimaryKey = true
result1.AddRow(newEntry);
newEntry.name = "test3"; // STRING - isPrimaryKey = true
newEntry.value = "test 3"; // STRING - isPrimaryKey = true
result1.AddRow(newEntry);
var param = {
table: result1 /* INFOTABLE */
};
var result = Resources["InfoTableFunctions"].ToJSON(param);
result.array = result.rows;
delete result.rows;
delete result.dataShape;
{
"array": [
{
"name": "test1",
"value": "test 1"
},
{
"name": "test2",
"value": "test 2"
},
{
"name": "test3",
"value": "test 3"
}
]
}
Could you attach your service code here if still not getting output without DataShape.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I am not allowed share the code.
But mine is a nested JSON.What you created is a straight forward one. It's not working with my output(nested)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @KN_9774047.
If you would like, we can open a case for further review of the problem. I will be happy to open the case on your behalf.
Regards.
--Sharon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you. It's help me!
![](/skins/images/695EE5AD3E567050FEDD72575855ED93/ptc_skin/images/icon_anonymous_message.png)