<?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>Cast/convert dictionary to array of variants</title><link>https://community.appian.com/discussions/f/rules/35528/cast-convert-dictionary-to-array-of-variants</link><description>The code above should dynamically be converted to 
 
 
 is that possible? Thanks in advance</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Cast/convert dictionary to array of variants</title><link>https://community.appian.com/thread/138475?ContentTypeID=1</link><pubDate>Mon, 22 Jul 2024 21:04:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:208b97af-37c6-4943-8e88-7678c8fb0452</guid><dc:creator>Silas. B. Ferreira</dc:creator><description>&lt;p&gt;Wow! That is it, it definitely works like a charm. Many thanks!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cast/convert dictionary to array of variants</title><link>https://community.appian.com/thread/138474?ContentTypeID=1</link><pubDate>Mon, 22 Jul 2024 21:01:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fc0a2c29-e4a3-4cbf-8ac8-b6968d5e9c26</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Oh, I just remembered there&amp;#39;s a cleaner way to do this using a!update() (which can inject a new property into an existing dictionary or map), so no need to manually construct a JSON string to back-convert.&amp;nbsp; See below:&lt;br /&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!localVariables(
  local!originalDictionary: {
    &amp;#39;a&amp;#39;: true,
    &amp;#39;b&amp;#39;: true,
    &amp;#39;c&amp;#39;: false,
    &amp;#39;d&amp;#39;: false
  },
  
  local!keys: a!keys(local!originalDictionary),
  
  a!forEach(
    local!keys,
    
    a!update(
      data: a!map(),
      index: fv!item,
      value: property(local!originalDictionary, fv!item)
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1721682083798v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cast/convert dictionary to array of variants</title><link>https://community.appian.com/thread/138473?ContentTypeID=1</link><pubDate>Mon, 22 Jul 2024 20:54:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c6b17580-fa23-441c-bd66-b5d5d7f9bbc9</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I guess it takes a little trickery to get the plaintext key name to be the key in a new dictionary, but if we (for instance) use JSON as an intermediary step, that&amp;#39;ll pretty much do it for us...&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!localVariables(
  local!originalDictionary: {
    &amp;#39;a&amp;#39;: true,
    &amp;#39;b&amp;#39;: true,
    &amp;#39;c&amp;#39;: false,
    &amp;#39;d&amp;#39;: false
  },
  
  local!keys: a!keys(local!originalDictionary),
  
  a!forEach(
    local!keys,
    
    /* note: double quotes have to be handled carefully here */
    a!fromJson(
      &amp;quot;{&amp;quot;&amp;quot;&amp;quot; &amp;amp; fv!item &amp;amp; &amp;quot;&amp;quot;&amp;quot;:&amp;quot; &amp;amp; property(local!originalDictionary, fv!item) &amp;amp; &amp;quot;}&amp;quot;
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="/resized-image/__size/640x480/__key/communityserver-discussions-components-files/15/pastedimage1721681662996v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cast/convert dictionary to array of variants</title><link>https://community.appian.com/thread/138471?ContentTypeID=1</link><pubDate>Mon, 22 Jul 2024 20:46:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8ddb674f-330e-4e79-b4af-d3a20ac6deb0</guid><dc:creator>Silas. B. Ferreira</dc:creator><description>&lt;p&gt;Could you please give me an example how can I create a&amp;nbsp;&lt;span&gt;set of new dictionaries? I am trying with a!forEach&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cast/convert dictionary to array of variants</title><link>https://community.appian.com/thread/138470?ContentTypeID=1</link><pubDate>Mon, 22 Jul 2024 20:26:16 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1787bf66-a9fb-4b0f-82ef-18944459cd37</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;What&amp;#39;s your use case?&lt;/p&gt;
&lt;p&gt;Depending on the particulars, I expect you could probably utilize &lt;em&gt;&lt;strong&gt;a!keys()&lt;/strong&gt;&lt;/em&gt; to get the keys from the original dictionary, then iterate over that list, creating a set of new dictionaries each containing just one property from the original.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>