<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to extract dynamic key  from nested json? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620966#M215850</link>
    <description>&lt;P&gt;Thanks for the reply&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;I need cluster names in a table not hosts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;cluster&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;DIV class=""&gt;xyz2&lt;/DIV&gt;&lt;DIV class=""&gt;xyz3&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2022 19:28:24 GMT</pubDate>
    <dc:creator>directtv999</dc:creator>
    <dc:date>2022-11-15T19:28:24Z</dc:date>
    <item>
      <title>How to extract dynamic key  from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620749#M215782</link>
      <description>&lt;P&gt;sample json:&lt;/P&gt;
&lt;P&gt;Hosts: { [-]&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Nodepool1: { [-]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Cluster: xyz1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Accountid: idxyz&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Nodepool3: { [-]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Cluster: xyz1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Accountid: idxyz&lt;BR /&gt;&amp;nbsp; &amp;nbsp;Nodepool5: { [-]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Cluster: xyz1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Accountid: idxyz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;am trying below query but it display list of servers but missing few servers randomly, please correct the query if am missing something.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=index1 | eval cluster="" |  foreach hosts.*.cluster [| eval cluster=isnotnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,cluster)] | table cluster&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 14 Nov 2022 14:40:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620749#M215782</guid>
      <dc:creator>directtv999</dc:creator>
      <dc:date>2022-11-14T14:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract dynamic key  from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620782#M215787</link>
      <description>&lt;P&gt;ltt&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 18:20:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620782#M215787</guid>
      <dc:creator>directtv999</dc:creator>
      <dc:date>2022-11-14T18:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract dynamic key  from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620869#M215817</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/251247"&gt;@directtv999&lt;/a&gt;&amp;nbsp;It is important to illustrate data using raw, conformant format (anonymize as needed); these Splunk formatted forms are difficult for others to parse. &amp;nbsp;In fact, the illustrated form is not even correct in Splunk highlighted format because they are not enclosed properly.&lt;/P&gt;&lt;P&gt;Additionally, it is impossible to "correct" anything unless we know what is "incorrect". &amp;nbsp;You should explain what you are trying to do with your sample code, and use samples to illustrate what exactly are "missing".&lt;/P&gt;&lt;P&gt;Further more, your illustrated sample SPL will not be "missing a few servers randomly." &amp;nbsp;It will not give any result because your sample data contains field names like Hosts.*.Cluster (capital H and C) but your code is iterating over hosts.*.cluster (lower case h and c). &amp;nbsp;Even if you correct for capitalization, it will produce an error "&lt;SPAN&gt;Fields cannot be assigned a boolean result."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The point is, when you post a question, you must accurately reflect the format of your data, illustrate accurate syntax of your attempted SPL, describe expected results - using mockup if necessary, illustrate output from sample SPL, then explain why the output does not meet your expectation. &amp;nbsp;It is unfair to expect volunteers in this forum to be mind readers.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;This said, I am willing to give mind reading a try. &amp;nbsp;If I guess the bracket closures correctly, then reverse engineer your illustrated data, it looks something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"Hosts": {
   "Nodepool1": {
       "Cluster": "xyz1",
       "Accountid": "idxyz"
       },
   "Nodepool3": {
      "Cluster": "xyz1",
     "Accountid": "idxyz"
     },
   "Nodepool5": {
     "Cluster": "xyz1",
    "Accountid": "idxyz"
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Then, I try to speculate the correct form of your sample SPL,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval cluster=""
| foreach Hosts.*.Cluster
 [| eval cluster=if(isnotnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'), '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', cluster)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem, then, is that &lt;FONT face="andale mono,times"&gt;cluster&lt;/FONT&gt; is single valued; with each iteration, you only get the current &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; value. &amp;nbsp;By the end of iteration, cluster will always be the last &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; value. &amp;nbsp;Try this instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval cluster=""
| foreach Hosts.*.Cluster
 [| eval cluster = mvappend(cluster, if(isnotnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'), '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', cluster))]
| table cluster&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Out of the corrected raw event, the above should give&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;cluster&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 15 Nov 2022 10:45:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620869#M215817</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-11-15T10:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract dynamic key  from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620873#M215821</link>
      <description>&lt;P&gt;I support everything&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;has said about providing clear and complete questions.&lt;/P&gt;&lt;P&gt;Having said that, if I understood correctly, you want the host names, i.e. the dynamic key, not the contents of the Cluster field? (Am I mind-reading? &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;)&lt;/P&gt;&lt;P&gt;If so, try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval hosts=""
| foreach Hosts.*.*
 [| eval hosts = mvdedup(mvappend(hosts, if(isnotnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'), "&amp;lt;&amp;lt;MATCHSEG1&amp;gt;&amp;gt;", hosts)))]
| table hosts&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 11:02:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620873#M215821</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-11-15T11:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract dynamic key  from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620966#M215850</link>
      <description>&lt;P&gt;Thanks for the reply&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;I need cluster names in a table not hosts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;cluster&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;DIV class=""&gt;xyz2&lt;/DIV&gt;&lt;DIV class=""&gt;xyz3&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 19:28:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620966#M215850</guid>
      <dc:creator>directtv999</dc:creator>
      <dc:date>2022-11-15T19:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract dynamic key  from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620967#M215851</link>
      <description>&lt;P&gt;Appreciate your response&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;will try to be more clear from next time. I tried your query and I can see the missing clusters working as expected and listing all the clusters for each event.&lt;/P&gt;&lt;P&gt;I want only unique values from all events for ex below table I tried dedup but no luck&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;cluster&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;DIV class=""&gt;xyz2&lt;/DIV&gt;&lt;DIV class=""&gt;xyz3&lt;/DIV&gt;&lt;DIV class=""&gt;xyz4&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your query is giving below output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;cluster&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;DIV class=""&gt;xyz2&lt;/DIV&gt;&lt;DIV class=""&gt;xyz3&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;xyz2&lt;/DIV&gt;&lt;DIV class=""&gt;xyz3&lt;/DIV&gt;&lt;DIV class=""&gt;xyz4&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;DIV class=""&gt;xyz2&lt;/DIV&gt;&lt;DIV class=""&gt;xyz4&lt;/DIV&gt;&lt;DIV class=""&gt;xyz1&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 19:52:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/620967#M215851</guid>
      <dc:creator>directtv999</dc:creator>
      <dc:date>2022-11-15T19:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract dynamic key  from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/621195#M215937</link>
      <description>&lt;P&gt;Have you considered&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.0.2/SearchReference/Multivaluefunctions#values.28X.29" target="_blank"&gt;values&lt;/A&gt;&amp;nbsp;function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval cluster=""
| foreach Hosts.*.Cluster
 [| eval cluster = mvappend(cluster, if(isnotnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'), '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', cluster))]
| stats values(cluster) as cluster&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 07:42:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/621195#M215937</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-11-17T07:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract dynamic key  from nested json?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/621200#M215940</link>
      <description>&lt;P&gt;You could use mvdedup (as I suggested in my otherwise incorrect solution)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval cluster=""
| foreach Hosts.*.Cluster
 [| eval cluster = mvdedup(mvappend(cluster, if(isnotnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'), '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', cluster)))]
| table cluster&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 08:45:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-dynamic-key-from-nested-json/m-p/621200#M215940</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-11-17T08:45:27Z</dc:date>
    </item>
  </channel>
</rss>

