<?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 count the number of event based on JSON field structure/keys in Splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-the-number-of-event-based-on-JSON-field-structure/m-p/540704#M153000</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231093"&gt;@samgol&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can get an approximate count by JSON key schema using something like this:&lt;/P&gt;&lt;P&gt;| fields data&lt;BR /&gt;| spath input=data&lt;BR /&gt;| fields - data&lt;BR /&gt;| foreach * [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;="" ]&lt;BR /&gt;| fieldsummary&lt;BR /&gt;| fields field count&lt;BR /&gt;| mvcombine field&lt;/P&gt;&lt;P&gt;Note that two schemas with the same field counts will be combined into a single set.&lt;/P&gt;&lt;P&gt;Another possibility is removing values and normalizing them to "" in data before grouping:&lt;/P&gt;&lt;P&gt;| eval data=replace(data, "\" ?: ?(?:\"(?:\\\"|.*?)\"|[-\d\.eE]+)", "\":\"\"")&lt;BR /&gt;| stats count by data&lt;BR /&gt;&lt;BR /&gt;{"a": "b"} =&amp;gt; {"a":""}&lt;BR /&gt;{"d": "x", "h": "e"} =&amp;gt; {"d":"", "h":""}&lt;/P&gt;&lt;P&gt;data&amp;nbsp; &amp;nbsp; count&lt;BR /&gt;{"a":""}&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;{"d":"", "h":""}&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;</description>
    <pubDate>Sun, 21 Feb 2021 06:38:39 GMT</pubDate>
    <dc:creator>tscroggins</dc:creator>
    <dc:date>2021-02-21T06:38:39Z</dc:date>
    <item>
      <title>How to count the number of event based on JSON field structure/keys in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-the-number-of-event-based-on-JSON-field-structure/m-p/538135#M152112</link>
      <description>&lt;P&gt;I want to count the number of occurrence of a specific JSON structure. For example in my event there is a field called&amp;nbsp;data&amp;nbsp;which its value is JSON . but this field can have a variety of structures. like:&lt;/P&gt;&lt;P&gt;data = {a: "b"}&lt;BR /&gt;data= {d: "x", h: "e"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now I want to know how many event has data with each JSON structure and I don't care about values only keys are matter.&amp;nbsp; So I want to count JSON that has similar keys.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 18:20:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-the-number-of-event-based-on-JSON-field-structure/m-p/538135#M152112</guid>
      <dc:creator>samgol</dc:creator>
      <dc:date>2021-02-03T18:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of event based on JSON field structure/keys in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-the-number-of-event-based-on-JSON-field-structure/m-p/540704#M153000</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231093"&gt;@samgol&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can get an approximate count by JSON key schema using something like this:&lt;/P&gt;&lt;P&gt;| fields data&lt;BR /&gt;| spath input=data&lt;BR /&gt;| fields - data&lt;BR /&gt;| foreach * [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;="" ]&lt;BR /&gt;| fieldsummary&lt;BR /&gt;| fields field count&lt;BR /&gt;| mvcombine field&lt;/P&gt;&lt;P&gt;Note that two schemas with the same field counts will be combined into a single set.&lt;/P&gt;&lt;P&gt;Another possibility is removing values and normalizing them to "" in data before grouping:&lt;/P&gt;&lt;P&gt;| eval data=replace(data, "\" ?: ?(?:\"(?:\\\"|.*?)\"|[-\d\.eE]+)", "\":\"\"")&lt;BR /&gt;| stats count by data&lt;BR /&gt;&lt;BR /&gt;{"a": "b"} =&amp;gt; {"a":""}&lt;BR /&gt;{"d": "x", "h": "e"} =&amp;gt; {"d":"", "h":""}&lt;/P&gt;&lt;P&gt;data&amp;nbsp; &amp;nbsp; count&lt;BR /&gt;{"a":""}&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;{"d":"", "h":""}&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;</description>
      <pubDate>Sun, 21 Feb 2021 06:38:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-the-number-of-event-based-on-JSON-field-structure/m-p/540704#M153000</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2021-02-21T06:38:39Z</dc:date>
    </item>
  </channel>
</rss>

