<?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 loop through json array based on expression and create counter in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469332#M132080</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;index=myIndex latest=+5h "extraFields{}.aimId"="innersource" "extraFields{}.prData.prResponse.values{}.author.user.name"="f401950" 
| spath path=extraFields{}.prData.prResponse.values{}.author.user output=user
| stats count by user
| spath input=user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I see, how about this?&lt;/P&gt;</description>
    <pubDate>Mon, 06 Apr 2020 21:46:57 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-04-06T21:46:57Z</dc:date>
    <item>
      <title>how to loop through json array based on expression and create counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469331#M132079</link>
      <description>&lt;P&gt;i'm hardcoding some data like names, where i will pass in a token in the future, to create a simple example of what i'm trying to achieve.  I want to loop through all values, which has objects containing the data.  Each field i loop through, i want to write an if statement to see if it matches what i'm expecting, if so increment the counter, else leave it the same.  Here is my data and what i have so far, weird part is the match or even == doesn't work for me here.  It should be at least 2 for sum, but nameTotal should have gotten that right at least? If i remove the stats (cause it loses my nameTotal field, nameTotal is always 0 meaning my if statement's never was true which means '&amp;lt;&amp;gt;' isn't right?, not sure what the variable is that i'm looking for from it.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=myIndex latest=+5h "extraFields{}.aimId"="innersource"  "extraFields{}.prData.prResponse.values{}.author.user.name"="f401950" &lt;BR /&gt;
| eval nameTotal= 0&lt;BR /&gt;
| foreach "extraFields{}.prData.prResponse.values{}.author.user.name" &lt;BR /&gt;
    [eval names=if(match('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', "f401950"), nameTotal+1, nameTotal)]&lt;BR /&gt;
| stats sum(names) as totalPrs&lt;BR /&gt;
| table totalPrs, nameTotal&lt;/CODE&gt;&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Results: &lt;BR /&gt;
totalPrs | nameTotal&lt;BR /&gt;
1             | &lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;&lt;EM&gt;Sample of my data&lt;/EM&gt;&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8647iE0D553156958AE11/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2020 21:23:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469331#M132079</guid>
      <dc:creator>gpSplunk123</dc:creator>
      <dc:date>2020-04-06T21:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to loop through json array based on expression and create counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469332#M132080</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=myIndex latest=+5h "extraFields{}.aimId"="innersource" "extraFields{}.prData.prResponse.values{}.author.user.name"="f401950" 
| spath path=extraFields{}.prData.prResponse.values{}.author.user output=user
| stats count by user
| spath input=user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I see, how about this?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2020 21:46:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469332#M132080</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-06T21:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to loop through json array based on expression and create counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469333#M132081</link>
      <description>&lt;P&gt;thanks! that worked really well!, is there a way i can append more columns based on a subsearch? cause i know stats loses my fields if it's not included in it.  I don't want to add it as part of the "by" because it'll throw the data off.  I just wanted to give more meta data based on the name, like gender, etc.  Here's a snippet of what i was trying to achieve.  I want to add name + email as part of the table's results, without modifying the results.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myIndex latest=+5h "extraFields{}.aimId"="innersource"  "extraFields{}.prData.prResponse.values{}.author.user.name"="*" 
| spath path=extraFields{}.prData.prResponse.values{}.author.user.name output=employeeId
| spath path=extraFields{}.prData.prResponse.values{}.author.user.displayName output=name
| spath path=extraFields{}.prData.prResponse.values{}.author.user.emailAddress output=email
| stats count by employeeId, name, email
| sort -count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Apr 2020 22:01:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469333#M132081</guid>
      <dc:creator>gpSplunk123</dc:creator>
      <dc:date>2020-04-06T22:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to loop through json array based on expression and create counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469334#M132082</link>
      <description>&lt;P&gt;check my updated answer.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2020 22:05:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469334#M132082</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-06T22:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to loop through json array based on expression and create counter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469335#M132083</link>
      <description>&lt;P&gt;that worked, thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2020 22:29:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-loop-through-json-array-based-on-expression-and-create/m-p/469335#M132083</guid>
      <dc:creator>gpSplunk123</dc:creator>
      <dc:date>2020-04-06T22:29:34Z</dc:date>
    </item>
  </channel>
</rss>

