<?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 build stats on JSON data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429145#M122750</link>
    <description>&lt;P&gt;@developer_de, what is the desired output? Following is the output I get when I try the following run anywhere search with the data similar to that provided by you.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;id             nativeResponseSent   nativeRequestReceived
180528_090129   3                   1
180528_090203   1                   2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the run anywhere search with dummy data as per the question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{
     \"ts\":1527498793267,
     \"version\":\"1.12.7\",
     \"data\":{
        \"myList\":[
           {
              \"id\":\"180528_090203\",
              \"nativeRequestReceived\":2,
              \"nativeResponseSent\":1
           },
           {
              \"id\":\"180528_090129\",
              \"nativeRequestReceived\":1,
              \"nativeResponseSent\":3
           }
        ],
        \"freemem\":6534152192
     },
     \"time\":\"2018-05-28T09:13:13.267Z\",
     \"v\":0
  }" 
| spath 
| rename data.myList{}.* as *
| eval mvfield=mvzip(id,mvzip(nativeResponseSent,nativeRequestReceived))
| fields - _*
| fields mvfield 
| mvexpand mvfield
| makemv mvfield delim=","
| eval id=mvindex(mvfield,0), nativeResponseSent=mvindex(mvfield,1), nativeRequestReceived=mvindex(mvfield,2)
| fields - mvfield
| stats sum(nativeResponseSent) as nativeResponseSent sum(nativeRequestReceived) as nativeRequestReceived by id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 May 2018 21:30:28 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2018-05-28T21:30:28Z</dc:date>
    <item>
      <title>How to build stats on JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429144#M122749</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I would like to get help on applying stats on the following JSON data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; {
    "ts":1527498793267,
    "version":"1.12.7",
    "data":{
       "myList":[
          {
             "id":"180528_090203",
             "nativeRequestReceived":1,
             "nativeResponseSent":1
          },
          {
             "id":"180528_090129",
             "nativeRequestReceived":1,
             "nativeResponseSent":1
          }
       ],
       "freemem":6534152192
    },
    "time":"2018-05-28T09:13:13.267Z",
    "v":0
 }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I started writing the query as written below, but it doesn't give desired result. split function is grouping same values of nativeResponseSent and nativeRequestReceived together.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;input data | rename data.myList{}.* as * | eval mvfield=mvzip($id$,mvzip($nativeResponseSent$,$nativeRequestReceived$)) | fields mvfield | mvexpand mvfield | eval mvfield=split(mvfield,",") | eval id=mvindex(mvfield,0) | eval nativeResponseSent=mvindex(mvfield,1) | eval nativeRequestReceived=mvindex(mvfield,2) | stats sum(nativeResponseSent) sum(nativeRequestReceived) by id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 May 2018 20:21:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429144#M122749</guid>
      <dc:creator>developer_de</dc:creator>
      <dc:date>2018-05-28T20:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to build stats on JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429145#M122750</link>
      <description>&lt;P&gt;@developer_de, what is the desired output? Following is the output I get when I try the following run anywhere search with the data similar to that provided by you.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;id             nativeResponseSent   nativeRequestReceived
180528_090129   3                   1
180528_090203   1                   2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the run anywhere search with dummy data as per the question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{
     \"ts\":1527498793267,
     \"version\":\"1.12.7\",
     \"data\":{
        \"myList\":[
           {
              \"id\":\"180528_090203\",
              \"nativeRequestReceived\":2,
              \"nativeResponseSent\":1
           },
           {
              \"id\":\"180528_090129\",
              \"nativeRequestReceived\":1,
              \"nativeResponseSent\":3
           }
        ],
        \"freemem\":6534152192
     },
     \"time\":\"2018-05-28T09:13:13.267Z\",
     \"v\":0
  }" 
| spath 
| rename data.myList{}.* as *
| eval mvfield=mvzip(id,mvzip(nativeResponseSent,nativeRequestReceived))
| fields - _*
| fields mvfield 
| mvexpand mvfield
| makemv mvfield delim=","
| eval id=mvindex(mvfield,0), nativeResponseSent=mvindex(mvfield,1), nativeRequestReceived=mvindex(mvfield,2)
| fields - mvfield
| stats sum(nativeResponseSent) as nativeResponseSent sum(nativeRequestReceived) as nativeRequestReceived by id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 May 2018 21:30:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429145#M122750</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-28T21:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to build stats on JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429146#M122751</link>
      <description>&lt;P&gt;It works fine .. thanks !!&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 22:18:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429146#M122751</guid>
      <dc:creator>developer_de</dc:creator>
      <dc:date>2018-05-28T22:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to build stats on JSON data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429147#M122752</link>
      <description>&lt;P&gt;@developer_de I have converted my comment to answer. Please accept to mark this as answered.&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 05:13:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-build-stats-on-JSON-data/m-p/429147#M122752</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-29T05:13:05Z</dc:date>
    </item>
  </channel>
</rss>

