<?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 create a chart that shows the JSON count by fields within an object? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402105#M116365</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your index&amp;gt; |  rex field=_raw "count:(?&amp;lt;count&amp;gt;.*)" max_match=0 |  rex field=_raw "resource:(?&amp;lt;resource&amp;gt;.*)" max_match=0| eval count=trim(count)|eval resource=trim(resource) |eval fields = mvzip(count,resource) 
| mvexpand fields 
| rex field=fields "(?&amp;lt;count&amp;gt;\w+),(?&amp;lt;resource&amp;gt;\w+)" 
|timechart values(count) by resource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try this if you are not sure about your json field, ideally @renjith.nair 's solution and spath is the correct way to go about this&lt;/P&gt;</description>
    <pubDate>Sat, 23 Jun 2018 08:27:36 GMT</pubDate>
    <dc:creator>Sukisen1981</dc:creator>
    <dc:date>2018-06-23T08:27:36Z</dc:date>
    <item>
      <title>How to create a chart that shows the JSON count by fields within an object?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402102#M116362</link>
      <description>&lt;P&gt;Each line of my log has the following json construct&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{        resourceUsage: [   
        {
         cloud:  AWS    
         count:  34 
         resource:   EC2_INSTANCE   
        }   


        {   
         cloud:  AWS    
         count:  3  
         resource:   NAT_GATEWAY    
        }
      ]

}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want create a time chart that shows sum (resourceUsage.count)  by resourceUsage.resource eg. &lt;CODE&gt;EC2_INSTANCE = 51, NAT_GATEWAY=25&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;My query which doesn't work looks like this  timechart span=1d sum(resourceUsage{}.count) by resourceUsage{}.resource&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2018 00:39:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402102#M116362</guid>
      <dc:creator>splunk_novice</dc:creator>
      <dc:date>2018-06-23T00:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a chart that shows the JSON count by fields within an object?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402103#M116363</link>
      <description>&lt;P&gt;Hi, have you tried spath - &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.1/SearchReference/Spath"&gt;http://docs.splunk.com/Documentation/Splunk/7.1.1/SearchReference/Spath&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2018 07:53:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402103#M116363</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2018-06-23T07:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a chart that shows the JSON count by fields within an object?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402104#M116364</link>
      <description>&lt;P&gt;Hi @splunk_novice,&lt;/P&gt;

&lt;P&gt;Hope this helps. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;        | makeresults |eval json="{
                \"resourceUsage\":    [    
                     {
                        \"cloud\":     \"AWS\",
                        \"count\":     34,    
                        \"resource\":  \"EC2_INSTANCE\"
                     }, 
                     {    
                        \"cloud\":     \"AWS\",
                        \"count\":     3,    
                        \"resource\":  \"NAT_GATEWAY\"
                     },
                     {    
                        \"cloud\":     \"AWS\",
                        \"count\":     10,    
                        \"resource\":  \"EC2_INSTANCE\"
                     },
                     {    
                        \"cloud\":     \"AWS\",
                        \"count\":     22,    
                        \"resource\":  \"NAT_GATEWAY\"
                     },
                     {    
                        \"cloud\":     \"AWS\",
                        \"count\":     7,    
                        \"resource\":  \"EC2_INSTANCE\"
                     }               
                   ]
            }"
| spath input=json|fields - json|rename resourceUsage{}.resource  as resource,resourceUsage{}.count as count
|eval zip=mvzip(resource,count)
|fields _time,zip| mvexpand zip|eval splitted=split(zip,",")|eval resource=mvindex(splitted,0)|eval count=mvindex(splitted,1)
|table _time resource,count|timechart sum(count) by resource
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Jun 2018 08:10:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402104#M116364</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-06-23T08:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a chart that shows the JSON count by fields within an object?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402105#M116365</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your index&amp;gt; |  rex field=_raw "count:(?&amp;lt;count&amp;gt;.*)" max_match=0 |  rex field=_raw "resource:(?&amp;lt;resource&amp;gt;.*)" max_match=0| eval count=trim(count)|eval resource=trim(resource) |eval fields = mvzip(count,resource) 
| mvexpand fields 
| rex field=fields "(?&amp;lt;count&amp;gt;\w+),(?&amp;lt;resource&amp;gt;\w+)" 
|timechart values(count) by resource
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try this if you are not sure about your json field, ideally @renjith.nair 's solution and spath is the correct way to go about this&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2018 08:27:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402105#M116365</guid>
      <dc:creator>Sukisen1981</dc:creator>
      <dc:date>2018-06-23T08:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a chart that shows the JSON count by fields within an object?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402106#M116366</link>
      <description>&lt;P&gt;Thanks renjith, worked like a charm.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2018 18:55:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-a-chart-that-shows-the-JSON-count-by-fields-within/m-p/402106#M116366</guid>
      <dc:creator>splunk_novice</dc:creator>
      <dc:date>2018-06-23T18:55:51Z</dc:date>
    </item>
  </channel>
</rss>

