<?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 do we count the fields inside a JSON array? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-count-the-fields-inside-a-JSON-array/m-p/279435#M84409</link>
    <description>&lt;P&gt;Thanks for the suggestion martin_mueller.  We got what we wanted by using the following.&lt;/P&gt;

&lt;P&gt;index="test_index" | spath input=log &lt;BR /&gt;
| regex templateId = "10|15"&lt;BR /&gt;
| stats count(eval(source == "mail")) AS COUNT by id,messages{}&lt;/P&gt;</description>
    <pubDate>Mon, 11 Apr 2016 17:51:46 GMT</pubDate>
    <dc:creator>yahoohunk</dc:creator>
    <dc:date>2016-04-11T17:51:46Z</dc:date>
    <item>
      <title>How do we count the fields inside a JSON array?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-count-the-fields-inside-a-JSON-array/m-p/279433#M84407</link>
      <description>&lt;P&gt;Each log entry contains some json.  There is a field that is an array.  I want to count the items in that array.&lt;/P&gt;

&lt;P&gt;Example json data&lt;BR /&gt;
{&lt;BR /&gt;
  "field1": "sample",&lt;BR /&gt;
  "messages": [&lt;BR /&gt;
      "noop",&lt;BR /&gt;
      "missing",&lt;BR /&gt;
      "error",&lt;BR /&gt;
      "unknown"&lt;BR /&gt;
  ]&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;We've tried index="test_index" | spath input=log | regex id = "a|b" | stats count(messages)&lt;/P&gt;

&lt;P&gt;Our desired output is something like:&lt;BR /&gt;
id      message      count&lt;BR /&gt;
a       noop              5&lt;BR /&gt;
a       error               8&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 23:02:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-count-the-fields-inside-a-JSON-array/m-p/279433#M84407</guid>
      <dc:creator>yahoohunk</dc:creator>
      <dc:date>2016-04-08T23:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do we count the fields inside a JSON array?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-count-the-fields-inside-a-JSON-array/m-p/279434#M84408</link>
      <description>&lt;P&gt;Assuming the array was extracted by the &lt;CODE&gt;spath&lt;/CODE&gt; into the field &lt;CODE&gt;messages{}&lt;/CODE&gt;, you can do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | spath input=log | rename messages{} as messages | eval message_count = mvcount(messages) | stats sum(message_count)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Apr 2016 23:45:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-count-the-fields-inside-a-JSON-array/m-p/279434#M84408</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-04-08T23:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do we count the fields inside a JSON array?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-we-count-the-fields-inside-a-JSON-array/m-p/279435#M84409</link>
      <description>&lt;P&gt;Thanks for the suggestion martin_mueller.  We got what we wanted by using the following.&lt;/P&gt;

&lt;P&gt;index="test_index" | spath input=log &lt;BR /&gt;
| regex templateId = "10|15"&lt;BR /&gt;
| stats count(eval(source == "mail")) AS COUNT by id,messages{}&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 17:51:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-we-count-the-fields-inside-a-JSON-array/m-p/279435#M84409</guid>
      <dc:creator>yahoohunk</dc:creator>
      <dc:date>2016-04-11T17:51:46Z</dc:date>
    </item>
  </channel>
</rss>

