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

About Convert JSON file to Infotable

SOLVED
Highlighted
Level 1

About Convert JSON file to Infotable

I follow the document: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS179012 to convert JSON file to Infotable, so I:

1. Create the Datashape based on the JSON key and value.

2. Create the service to getJSON file, and the code is:

var params = {

proxyScheme: undefined /* STRING */,

headers: undefined /* JSON */,

ignoreSSLErrors: true /* BOOLEAN */,

useNTLM: undefined /* BOOLEAN */,

workstation: undefined /* STRING */,

useProxy: undefined /* BOOLEAN */,

withCookies: undefined /* BOOLEAN */,

proxyHost: undefined /* STRING */,

url:"http://servername/rest/sql/list/site/",

timeout: undefined /* NUMBER */,

proxyPort: undefined /* INTEGER */,

password: undefined /* STRING */,

domain: undefined /* STRING */,

username: undefined /* STRING */

};

// result: JSON

var data = Resources["ContentLoaderFunctions"].GetJSON(params);

var params = {

infoTableName: undefined /* STRING */,

dataShapeName: "TestJSON" /* DATASHAPENAME */

};

// result: INFOTABLE

var jsonTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

for(var i=0;i<data.length;i++)

{

    jsonTable.AddRow({id:data.array.id, area:data.array.area, group:data.array.group, WS_name:data.array.WS_name, state:data.array.state, child:data.array.child});

}

//}

result = jsonTable;

3. After save and test, the result is an empty infotable.

Can anyone help?

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: About Convert JSON file to Infotable

Hi Mr. Cheung,

Please provide the structure of your JSON file? Do you have a arrays?

Usually, JSON content rows and use below code to convert to infotable

for(var i=0;i<data.length;i++)

{

    jsonTable.AddRow({id:data.rows.id, area:data.rows.area, group:data.rows.group, WS_name:data.rows.WS_name, state:data.rows.state, child:data.rows.child});

}

If still not works, please let me know.

BR,

Lily

3 REPLIES 3

Re: About Convert JSON file to Infotable

Hi Mr. Cheung,

Please provide the structure of your JSON file? Do you have a arrays?

Usually, JSON content rows and use below code to convert to infotable

for(var i=0;i<data.length;i++)

{

    jsonTable.AddRow({id:data.rows.id, area:data.rows.area, group:data.rows.group, WS_name:data.rows.WS_name, state:data.rows.state, child:data.rows.child});

}

If still not works, please let me know.

BR,

Lily

Re: About Convert JSON file to Infotable

Hi Lily,

Thank you for your kind reply.

Content of my JSON file is a bit different when using the GetJSON function. So I changed the AddRow function from ({Name:json.name })to ({Name:data.rows.name}, and then got the correct Infotable, thanks again.

XiaoYing

Re: About Convert JSON file to Infotable

Hi XiaoYing,

It's my pleasure.

Lily