<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/discussions/f/data/12809/how-to-create-json-parameter-based-on-cdt-of-array</link><description>Hello All, 
 I&amp;#39;m having some difficulty for creating Json parameter based on my cdt. Here is the scenario, 
 
 Suppose my CDT is as below 
 [ID:12,Identifier:&amp;quot;Abc&amp;quot;,Label:&amp;quot;NumberOfPages&amp;quot;,Value:&amp;quot;30&amp;quot;], 
 [ID:13,Identifier:&amp;quot;Pqr&amp;quot;,Label:&amp;quot;LastModified&amp;quot;,Value</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57414?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 15:06:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:84c0d68a-8783-4d9c-a85e-c3e463e158b3</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Fair point - presuming the original input is a CDT array with different &lt;span style="color:#0000ff;"&gt;Label&lt;/span&gt;s, we would want to handle the conversion in a loop.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;with(
  local!myCdt: {
    {
      ID: 12,
      Identifier: &amp;quot;Abc&amp;quot;,
      Label: &amp;quot;NumberOfPages&amp;quot;,
      Value: 30
    },
    {
      ID: 47,
      Identifier: &amp;quot;XYZ&amp;quot;,
      Label: &amp;quot;LastModified&amp;quot;,
      Value: today()
    }
  },
  
  local!customDictionary: a!toJson(
    a!forEach(
      local!myCdt,
      with(
        local!initialJson: a!toJson(
          {
            replaceWithLabel: fv!item.Value
          }
        ),
        
        local!convertedJson: substitute(
          local!initialJson,
          &amp;quot;replaceWithLabel&amp;quot;,
          fv!item.Label
        ),
        
        a!fromJson(local!convertedJson)
      )
    )
  ),
  
  local!customDictionary
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Output:&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;[{&amp;quot;NumberOfPages&amp;quot;:30},{&amp;quot;LastModified&amp;quot;:&amp;quot;2018-06-29Z&amp;quot;}]&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57413?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 14:23:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2b7ba4c7-3847-4f6d-9cc4-e0befb5c6a27</guid><dc:creator>chandu</dc:creator><description>If you want to user an array of CDT, the you need to user forEach to loop through the each record, else your json will be messed up.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57412?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 14:15:36 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b0e4595e-c206-41be-9e97-2837748672ce</guid><dc:creator>viveku3486</dc:creator><description>Hey Mike,&lt;br /&gt;
&lt;br /&gt;
Thanks for your quick responses and providing the help specific to what was needed. I really appreciate your efforts and time. You are CHAMP !!!&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57410?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 14:01:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ac2c022a-0577-40c1-97e3-5fe2f875433a</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;For this you would need some sort of custom code, as this isn&amp;#39;t really a use case a!toJson is intended to work with.&lt;/p&gt;
&lt;p&gt;The only suggestion I can think of is, use your original CDT and formulate a custom dictionary and then convert that to JSON, and afterwards manually swap out values within the resulting JSON string.&amp;nbsp; Note that this is a little complicated and might not scale very well.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;load(
  local!myCdt: {
    ID: 12,
    Identifier: &amp;quot;Abc&amp;quot;,
    Label: &amp;quot;NumberOfPages&amp;quot;,
    Value: 30,
    LastModified: today()
  },
  
  local!customDictionary: {
    replaceWithLabel: local!myCdt.Value
  },
  
  local!initialJson: a!toJson(local!customDictionary),
  
  substitute(
    local!initialJson,
    &amp;quot;replaceWithLabel&amp;quot;,
    local!myCdt.Label
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Result:&lt;/p&gt;
&lt;pre&gt;{&amp;quot;NumberOfPages&amp;quot;:30}&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57409?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 13:59:43 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2fe9c268-6f71-4e7e-b01b-cdce0af60f75</guid><dc:creator>viveku3486</dc:creator><description>&lt;p&gt;&lt;a href="/cfs-file/__key/communityserver-discussions-components-files/16/4137.Capture.PNG"&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/16/4137.Capture.PNG" alt=" " /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57408?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 13:54:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8ffea9eb-7d87-45ce-abbd-2590d1fd9712</guid><dc:creator>viveku3486</dc:creator><description>Ok, Let me explain what I need exactly. Consider below is my CDT&lt;br /&gt;
&lt;br /&gt;
local!CDT:{&lt;br /&gt;
ID:12,&lt;br /&gt;
Identifier:&amp;quot;Abc&amp;quot;,&lt;br /&gt;
Label:&amp;quot;NumberOfPages&amp;quot; ,&lt;br /&gt;
Value:30&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now in the above CDT, We have total 4 fields i.e ID,Identifier,Label and Value. Now I need to convert the combination of Label and Value into Json format. i.e. My Value inside Label field is &amp;quot;NumberOfPages&amp;quot; and inside Value is &amp;quot;30&amp;quot;.So I want to merge this two values in the form of Json like&lt;br /&gt;
&lt;br /&gt;
{&amp;quot;NumberOfPages&amp;quot;:&amp;quot;30&amp;quot;}&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57407?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 13:44:06 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a8bf62ba-6ac9-4946-8317-4f107a6c444d</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Can you post an example of the code you&amp;#39;re using?&amp;nbsp; The result you describe getting from a!toJson is not consistent with how I have seen it works when passed an actual CDT.&lt;/p&gt;
&lt;p&gt;For example, this expression:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;load(
  local!myCdt: {
    ID: 12,
    Identifier: &amp;quot;Abc&amp;quot;,
    NumberOfPages: 30,
    LastModified: today()
  },
  
  a!toJson(local!myCdt)
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;produces the following output, which seems consistent with what you seem to be asking for:&lt;/p&gt;
&lt;pre&gt;{&amp;quot;ID&amp;quot;:12,&amp;quot;Identifier&amp;quot;:&amp;quot;Abc&amp;quot;,&amp;quot;NumberOfPages&amp;quot;:30,&amp;quot;LastModified&amp;quot;:&amp;quot;2018-06-29Z&amp;quot;}&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57406?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 13:38:56 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b57ee2c2-af2a-4add-abed-9606347df2fd</guid><dc:creator>viveku3486</dc:creator><description>Hey Mike,&lt;br /&gt;
&lt;br /&gt;
Yes I tried a!toJson() function but the issue here is related to the format of data which I need. While using a!toJson() it gives me the result like &lt;br /&gt;
&lt;br /&gt;
{&amp;quot;ID&amp;quot;:&amp;quot;12&amp;quot;,&amp;quot;Identifier&amp;quot;:&amp;quot;Abc&amp;quot;,&amp;quot;Label&amp;quot;:&amp;quot;NumberOfPages&amp;quot;,&amp;quot;Value&amp;quot;:&amp;quot;30&amp;quot;},&lt;br /&gt;
&lt;br /&gt;
[&amp;quot;ID&amp;quot;:13,&amp;quot;Identifier&amp;quot;:&amp;quot;Pqr&amp;quot;,&amp;quot;Label&amp;quot;:&amp;quot;LastModified&amp;quot;,&amp;quot;Value&amp;quot;:&amp;quot;2018-12-1&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
but I need something like &lt;br /&gt;
{&amp;quot;NumberOfPages&amp;quot;:&amp;quot;30&amp;quot;,LastModified&amp;quot;:&amp;quot;2018-12-11&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
which is the combination of Label and Value.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to create Json Parameter based on CDT of Array?</title><link>https://community.appian.com/thread/57405?ContentTypeID=1</link><pubDate>Fri, 29 Jun 2018 13:31:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:301ce736-e72f-40ad-b87f-2e4a1e223901</guid><dc:creator>Mike Schmitt</dc:creator><description>Have you tried a!toJson()?  If so, is it doing anything wrong in particular?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>