Need to convert ExecuteQuery result into an array of JSON object | Community
Skip to main content
Level 2
September 13, 2023
Solved

Need to convert ExecuteQuery result into an array of JSON object

  • September 13, 2023
  • 1 reply
  • 719 views

Hi All, 
I am trying to execute a query on one my ACC tables. I need to create an array of Json objects . Can someone help to do it dynamically if he has already done in the past

Table Structure : 

CountryService1Service2Service3
IndiaYesNoNo
MalaysiaNoYes Yes

 

Output that I am looking for :

[

{ Country:"India",

Service1:Yes

Service2:No

Service3:No},

{ Country:"Malaysia",

Service1:No

Service2:Yes

Service3:Yes}

]

 

@david--garcia 

Thanks

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AkshayAnand

Hi @rahulg12032086 

 

You can try the below code for your requirement.

 

var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1); logInfo(schemaName); var query = xtk.queryDef.create( <queryDef schema={vars.targetSchema} operation="select"> <select> <node expr="@country"/> <node expr="@Service1"/> <node expr="@Service2"/> <node expr="@Service3"/> </select> </queryDef> ); var resultSet = query.ExecuteQuery(); var Data=''; for each (var row in resultSet) { Data= Data + "{ Country ="+row.@country; "Service="+row.@Service1; "Service="+row.@Service2; "Service="+row.@Service3; "}"; } Data="["+Data+"]"; logInfo(Data);

1 reply

AkshayAnand
Community Advisor
AkshayAnandCommunity AdvisorAccepted solution
Community Advisor
September 13, 2023

Hi @rahulg12032086 

 

You can try the below code for your requirement.

 

var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1); logInfo(schemaName); var query = xtk.queryDef.create( <queryDef schema={vars.targetSchema} operation="select"> <select> <node expr="@country"/> <node expr="@Service1"/> <node expr="@Service2"/> <node expr="@Service3"/> </select> </queryDef> ); var resultSet = query.ExecuteQuery(); var Data=''; for each (var row in resultSet) { Data= Data + "{ Country ="+row.@country; "Service="+row.@Service1; "Service="+row.@Service2; "Service="+row.@Service3; "}"; } Data="["+Data+"]"; logInfo(Data);
Level 2
September 14, 2023

Thank you Akshay , This worked. !