<?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 I sum similarly named fields from nested JSON? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220946#M64920</link>
    <description>&lt;P&gt;Is this what you are looking for? If not please post a few samples and a more detailed JSON file.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search here
| spath input=yourJsonField
| stats sum(subdata*) as subdata* by id
| stats max(subdata*) as subdata*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example with some data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw = "
{ \"id\": \"theid\", \"subdata\": [ 
  { \"subname\": \"s1\", \"key1_foo\": 10, \"key1_bar\": 12, \"key2_foo\": 100, \"key2_bar\": 101}, 
  {\"subname\": \"s2\", \"key1_foo\": 20, \"key1_bar\": 24, \"key2_foo\": 200, \"key2_bar\": 202}
]
}
"
| spath input=_raw
| stats sum(subdata*) as subdata* by id
| stats max(subdata*) as subdata*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/1702i0F966EC409564D6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Aug 2016 10:54:55 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-08-10T10:54:55Z</dc:date>
    <item>
      <title>How do I sum similarly named fields from nested JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220944#M64918</link>
      <description>&lt;P&gt;I have JSON events with a sub list and want to sum similarly named fields for each event.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ "id": "theid", "subdata": [ { "subname": "s1", "key1_foo": 10, "key1_bar": 12, "key2_foo": 100, "key2_bar": 101}, {"subname": "s2", "key1_foo ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to &lt;CODE&gt;chart max(sum_of_key1*), max(sum_of_key2*)&lt;/CODE&gt; by the id&lt;BR /&gt;
and also by subname.&lt;/P&gt;

&lt;P&gt;Any info would be appreciated.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2016 23:52:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220944#M64918</guid>
      <dc:creator>unclethan</dc:creator>
      <dc:date>2016-08-09T23:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum similarly named fields from nested JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220945#M64919</link>
      <description>&lt;P&gt;This is my go to article for this use case:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Spath#Example_3:_Extract_and_expand_JSON_events_with_multi-valued_fields"&gt;https://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Spath#Example_3:_Extract_and_expand_JSON_events_with_multi-valued_fields&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 01:18:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220945#M64919</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-08-10T01:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum similarly named fields from nested JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220946#M64920</link>
      <description>&lt;P&gt;Is this what you are looking for? If not please post a few samples and a more detailed JSON file.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search here
| spath input=yourJsonField
| stats sum(subdata*) as subdata* by id
| stats max(subdata*) as subdata*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example with some data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw = "
{ \"id\": \"theid\", \"subdata\": [ 
  { \"subname\": \"s1\", \"key1_foo\": 10, \"key1_bar\": 12, \"key2_foo\": 100, \"key2_bar\": 101}, 
  {\"subname\": \"s2\", \"key1_foo\": 20, \"key1_bar\": 24, \"key2_foo\": 200, \"key2_bar\": 202}
]
}
"
| spath input=_raw
| stats sum(subdata*) as subdata* by id
| stats max(subdata*) as subdata*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/1702i0F966EC409564D6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 10:54:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220946#M64920</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-08-10T10:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum similarly named fields from nested JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220947#M64921</link>
      <description>&lt;P&gt;Sorry I wasn't clear.&lt;BR /&gt;
Your example gives a result per key1_* field, I need a sum over all the key1_fields, named key1, and the same for key2.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:34:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220947#M64921</guid>
      <dc:creator>unclethan</dc:creator>
      <dc:date>2020-09-29T10:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum similarly named fields from nested JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220948#M64922</link>
      <description>&lt;P&gt;If you have your data indexed as JSON, and all fields are extracted, this shoud work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename subdata{}.* as *
| stats sum(key1_*) as sum_key1_* sum(key2_*) as sum_key2_*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Aug 2016 20:25:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220948#M64922</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-10T20:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum similarly named fields from nested JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220949#M64923</link>
      <description>&lt;P&gt;as I mentioned above, the summation is meant to be across similar keys within the json object, not per-key, across events.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 20:31:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220949#M64923</guid>
      <dc:creator>unclethan</dc:creator>
      <dc:date>2016-08-10T20:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I sum similarly named fields from nested JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220950#M64924</link>
      <description>&lt;P&gt;Replace the ... with the root searches:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| spath 
| rename subdata{}.key1* as key1*
| stats sum(key1*) as key1* 
| addtotals key1* 
| append 
 [ 
 search ... 
 | spath 
 | rename subdata{}.key2* as key2*
 | stats sum(key2*) as key2* 
 | addtotals key2* 
 ] 
| transpose
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Aug 2016 22:05:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-sum-similarly-named-fields-from-nested-JSON/m-p/220950#M64924</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-08-10T22:05:43Z</dc:date>
    </item>
  </channel>
</rss>

