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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

How do I remove datashape field from below JSON output?

KN_9774047
5-Regular Member

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"
}

6 REPLIES 6
suverma
14-Alexandrite
(To:KN_9774047)

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

KN_9774047
5-Regular Member
(To:suverma)

Tried that way in Thingworx 9.0.3 but not working out.

 

datShape field is still showing up in the output

suverma
14-Alexandrite
(To:KN_9774047)

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:

 

 

Spoiler

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;

 

Spoiler
JSON Output:
{
"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.

KN_9774047
5-Regular Member
(To:suverma)

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)

slangley
23-Emerald II
(To:KN_9774047)

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

Thank you. It's help me!

Fábio Valente - Developer and Solution Architect
Announcements


Top Tags