<?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>JSON Key Lookup</title><link>https://community.appian.com/discussions/f/rules/9938/json-key-lookup</link><description>Hi there, Curious if anyone has any good suggestions on the below problem. We are trying to get the keys from a JSON array object. The keys unfortunately are dates and are dynamic. For example, the below works fine, but it&amp;#39;s hard-coding &amp;quot;09/03/2017&amp;quot;.</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: JSON Key Lookup</title><link>https://community.appian.com/thread/63311?ContentTypeID=1</link><pubDate>Tue, 11 Dec 2018 13:42:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f8dee3e9-d8ef-465c-a490-7f18f21bd272</guid><dc:creator>vijay</dc:creator><description>Hi, Please find the below code, little lengthy but might help to your requirement:&lt;br /&gt;
&lt;br /&gt;
with(&lt;br /&gt;
   local!json: &amp;quot;{&lt;br /&gt;
&amp;quot;&amp;quot;09/03/2017&amp;quot;&amp;quot;: {&lt;br /&gt;
&amp;quot;&amp;quot;total&amp;quot;&amp;quot;: 5&lt;br /&gt;
},&lt;br /&gt;
&amp;quot;&amp;quot;10/03/2017&amp;quot;&amp;quot;: {&lt;br /&gt;
&amp;quot;&amp;quot;total&amp;quot;&amp;quot;: 10&lt;br /&gt;
}&lt;br /&gt;
}&amp;quot;,&lt;br /&gt;
  /*Convert into Appian value*/&lt;br /&gt;
  local!data: a!fromJson(&lt;br /&gt;
    local!json&lt;br /&gt;
  ),&lt;br /&gt;
  /*Split to fetch key type date values*/&lt;br /&gt;
  local!divideTheData: split(&lt;br /&gt;
    split(&lt;br /&gt;
      local!data,&lt;br /&gt;
      &amp;quot;:&amp;quot;&lt;br /&gt;
    ),&lt;br /&gt;
    &amp;quot;,&amp;quot;&lt;br /&gt;
  ),&lt;br /&gt;
  /*To remove unwanted characters*/&lt;br /&gt;
  local!updatedData: a!forEach(&lt;br /&gt;
    local!divideTheData,&lt;br /&gt;
    stripwith(&lt;br /&gt;
      fv!item,&lt;br /&gt;
      &amp;quot;[&amp;quot;&lt;br /&gt;
    )&lt;br /&gt;
  ),&lt;br /&gt;
  local!fetchDesiredData: a!forEach(&lt;br /&gt;
    local!updatedData,&lt;br /&gt;
    if(&lt;br /&gt;
      find(&lt;br /&gt;
        &amp;quot;/&amp;quot;,&lt;br /&gt;
        fv!item&lt;br /&gt;
      ),&lt;br /&gt;
      true(),&lt;br /&gt;
      null&lt;br /&gt;
    )&lt;br /&gt;
  ),&lt;br /&gt;
  index(&lt;br /&gt;
    local!updatedData,&lt;br /&gt;
    where(&lt;br /&gt;
      local!fetchDesiredData&lt;br /&gt;
    )&lt;br /&gt;
  )&lt;br /&gt;
)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: JSON Key Lookup</title><link>https://community.appian.com/thread/63306?ContentTypeID=1</link><pubDate>Tue, 11 Dec 2018 11:07:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7db85e37-8769-4611-b028-fad04f045c50</guid><dc:creator>shubhamg0005</dc:creator><description>[Try this rule . I have made json from myself and it will gives all the key from Json ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
a!forEach(&lt;br /&gt;
    items: split(&lt;br /&gt;
    a!toJson(&lt;br /&gt;
      {&lt;br /&gt;
        x: 1,&lt;br /&gt;
        y: 2,&lt;br /&gt;
        z: 3&lt;br /&gt;
      }&lt;br /&gt;
    ),&lt;br /&gt;
    &amp;quot;,&amp;quot;&lt;br /&gt;
  ),&lt;br /&gt;
    expression: split(fv!item,&amp;quot;&amp;quot;&amp;quot;&amp;quot;)[2])&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: JSON Key Lookup</title><link>https://community.appian.com/thread/43870?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 19:33:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a176cf86-e58d-40fd-9b18-964c910407ee</guid><dc:creator>Josh</dc:creator><description>Here is an Appian implementation for your data model. Note that it could probably be cleaned up and it may not work for other data models! Also, you want the &amp;quot;values&amp;quot; here, the &amp;quot;keys&amp;quot; are the dates in your dictionary.&lt;br /&gt;&lt;br /&gt;with(&lt;br /&gt;  local!json: &amp;quot;{&lt;br /&gt;    &amp;quot;&amp;quot;09/03/2017&amp;quot;&amp;quot;: {&lt;br /&gt;      &amp;quot;&amp;quot;total&amp;quot;&amp;quot;: 5&lt;br /&gt;    },&lt;br /&gt;    &amp;quot;&amp;quot;10/03/2017&amp;quot;&amp;quot;: {&lt;br /&gt;      &amp;quot;&amp;quot;total&amp;quot;&amp;quot;: 5&lt;br /&gt;    }&lt;br /&gt;  }&amp;quot;,&lt;br /&gt;  local!dictionary: a!fromJson(local!json),&lt;br /&gt;  local!objects: split(tostring(local!dictionary), &amp;quot;,&amp;quot;),&lt;br /&gt;  local!keysRaw: apply(&lt;br /&gt;    mid(_, 1, 11),&lt;br /&gt;    local!objects&lt;br /&gt;  ),&lt;br /&gt;  local!keysStripped: apply(stripwith(_, &amp;quot;[]:&amp;quot;), local!keysRaw),&lt;br /&gt;  apply(index(local!dictionary, _, {}), local!keysStripped)&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: JSON Key Lookup</title><link>https://community.appian.com/thread/43867?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 16:02:58 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9e29c7ae-b4bf-4f4e-9b1a-0b76b1f8ae07</guid><dc:creator>PhilB</dc:creator><description>Oh and I should add that the date regex could definitely be tightened up - but works ok for this example.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: JSON Key Lookup</title><link>https://community.appian.com/thread/43866?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 15:59:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:36cc1d6f-cf3a-4025-89a3-3d2d45507ac5</guid><dc:creator>PhilB</dc:creator><description>Just FYI, to access the actual values in the response, just use dot notation (ie .total) on the closing bracket of the apply, or wrap the apply in an index().&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: JSON Key Lookup</title><link>https://community.appian.com/thread/43865?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2017 15:58:19 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:209e86d1-21bd-43e8-ab70-fba0435abd1b</guid><dc:creator>PhilB</dc:creator><description>I was going to suggest using a!jsonPath, but it appears it&amp;#39;s impossible to get the key names in that manner. Arguably the JSON here, whilst syntactically valid, isn&amp;#39;t really logically valid. However, it is possible to extract the keys from the JSON using a regex, and then loop over them - but it does require the regex plugin:&lt;br /&gt;&lt;br /&gt;= with(&lt;br /&gt;  local!json: &amp;quot;{&lt;br /&gt;    &amp;quot;&amp;quot;09/03/2017&amp;quot;&amp;quot;: {&lt;br /&gt;      &amp;quot;&amp;quot;total&amp;quot;&amp;quot;: 5&lt;br /&gt;    },&lt;br /&gt;    &amp;quot;&amp;quot;10/03/2017&amp;quot;&amp;quot;: {&lt;br /&gt;      &amp;quot;&amp;quot;total&amp;quot;&amp;quot;: 5&lt;br /&gt;    }&lt;br /&gt;  }&amp;quot;,&lt;br /&gt;  apply(&lt;br /&gt;    fn!index(&lt;br /&gt;      a!fromJson(&lt;br /&gt;        local!json&lt;br /&gt;      ),&lt;br /&gt;      _,&lt;br /&gt;      null&lt;br /&gt;    ),&lt;br /&gt;    fn!regexallmatches(&lt;br /&gt;      &amp;quot;([0-9]{2}\\/[0-9]{2}\\/[0-9]{4})&amp;quot;,&lt;br /&gt;      local!json&lt;br /&gt;    )&lt;br /&gt;  )&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>