Need to Convert the values into specific Json Format

Certified Associate Developer

Hello All,

 

I have a requirement to convert a CDT value into specific Json Format, Here is the scenario

 

Suppose there is variable called "initialCDT", Such as

 

local!initalCDT:{

{

type!abc(

Key:"NoOfPages",

Value:{1,2,3}

},

{

type!abc{

Key:"WordCount",

Value:{5,6,7}

}

}

 

Now I have some other variables as well holding some values but the the above variable can have dynamic number of Key Value pairs. So My requirement is to create a Json String like below

{

"Title":"Journey to West",

"StartDate":"2018-10-08",

"EndDate":2018-12-08",

"ProcessParameters":{

       "NoOfPages":{1,2,3},

       "WordCount":{5,6,7}

}

},

 

Here the ProcessParameter is made from the variable declared above and the format should be exactly the same, Otherwise the API method will  fail, Can someone please assist me here? Thanks in advance

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    You can use a!toJson to convert any KVP into a JSON string like the one your requirement specifies. If you have a CDT that holds the title, startdate, enddate, and process parameters, you could even do a toJson on the CDT itself. Otherwise, you can manually create a dictionary that holds all that data and then wrap it in a toJson. Sort of like this:

    a!toJson(
      {
         Title: ri!title,
         StartDate: ri!startDate,
         EndDate: ri!endDate,
         ProcessParameters: {
           NoOfPages: ri!numPages,
           WordCount: ri!wordCount
         }
      }
    )

     

  • 0
    Certified Associate Developer
    in reply to Sik-Kim
    Here the NoOfPages and WordCount are not fixed. There will be a list of labels available to the user from where user can select their desired labels and there respective values. So I have created a CDT have Key Value pair. Where Key contains the selected label and value contains its actual value. So I need to use that CDT inside ProcessParameters in such a way that It will reflect the output as mentioned above
Reply
  • 0
    Certified Associate Developer
    in reply to Sik-Kim
    Here the NoOfPages and WordCount are not fixed. There will be a list of labels available to the user from where user can select their desired labels and there respective values. So I have created a CDT have Key Value pair. Where Key contains the selected label and value contains its actual value. So I need to use that CDT inside ProcessParameters in such a way that It will reflect the output as mentioned above
Children
No Data