<?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 extract sum totals for data in a nested JSON object? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-sum-totals-for-data-in-a-nested-JSON-object/m-p/34021#M6120</link>
    <description>&lt;P&gt;I was sort of able to do this myself.  You may want to try&lt;/P&gt;

&lt;P&gt;Based on your example above:&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
 | spath input=some.request.complete actions{} | mvexpand actions{} | spath input=actions{} | stats sum("Bar.UPDATED") by "Foo.UPDATED"&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 11 May 2016 15:04:23 GMT</pubDate>
    <dc:creator>russellliss</dc:creator>
    <dc:date>2016-05-11T15:04:23Z</dc:date>
    <item>
      <title>How to extract sum totals for data in a nested JSON object?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-sum-totals-for-data-in-a-nested-JSON-object/m-p/34020#M6119</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;I have the following log line format (slightly edited for anonymity),&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2013-08-14T08:54:10.098+0100 [INFO] {process-0.1735} spin-processor - [TIMER] some.request.complete {"id":"a1b2c3d4e5","sequenceNo":2,"fooId":"f6g7h8i9j0","duration":2.981,"totalActions":170,"actions":{"Foo.UPDATED":1,"Bar.UPDATED":169}}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The bit my question relates to is the &lt;CODE&gt;actions&lt;/CODE&gt; key in the JSON object. Ultimately what I want is to get a table containing the sum total for each action type over a given time period, e.g.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;+----------------------+
| Action       | Total |
+----------------------+
| Foo.INSERTED | 2     |
| Foo.UPDATED  | 56    |
| Bar.INSERTED | 169   |
| Bar.UPDATED  | 5678  |
+----------------------+
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any idea how I would do this?&lt;/P&gt;

&lt;P&gt;The closest I've got so far is to manually do a &lt;CODE&gt;sum()&lt;/CODE&gt; on each type (as I'm already SPATHing the JSON), but the table it gives me is the wrong way round to what I want, e.g. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;+-----------------------------------------------------+
| sum(actions.Foo.UPDATED) | sum(actions.Bar.UPDATED) |
+-----------------------------------------------------+
| 56                       | 5678                     |
+-----------------------------------------------------+
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2013 08:16:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-sum-totals-for-data-in-a-nested-JSON-object/m-p/34020#M6119</guid>
      <dc:creator>stephenmelrose</dc:creator>
      <dc:date>2013-08-14T08:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract sum totals for data in a nested JSON object?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-sum-totals-for-data-in-a-nested-JSON-object/m-p/34021#M6120</link>
      <description>&lt;P&gt;I was sort of able to do this myself.  You may want to try&lt;/P&gt;

&lt;P&gt;Based on your example above:&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
 | spath input=some.request.complete actions{} | mvexpand actions{} | spath input=actions{} | stats sum("Bar.UPDATED") by "Foo.UPDATED"&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 15:04:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-sum-totals-for-data-in-a-nested-JSON-object/m-p/34021#M6120</guid>
      <dc:creator>russellliss</dc:creator>
      <dc:date>2016-05-11T15:04:23Z</dc:date>
    </item>
  </channel>
</rss>

