<?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: sum multiple value in a json in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/sum-multiple-value-in-a-json/m-p/390718#M69883</link>
    <description>&lt;P&gt;Hey 3vi,&lt;/P&gt;

&lt;P&gt;Using the raw data you provided, I've created a search that should give you the correct numbers you're looking for (you can copy and paste this into any Splunk instance):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval _raw =  ".success [{\"importo\":2,\"tipologiaOperazione\":\"AAA\"},{\"importo\":1.82,\"tipologiaOperazione\":\"BBB\"}, {\"importo\":1,\"tipologiaOperazione\":\"AAA\"}]"
| rex field=_raw max_match=0 "\"importo\"\:(?&amp;lt;importo&amp;gt;[^\,]+)\,\"tipologiaOperazione\"\:\"(?&amp;lt;tipologiaOperazione&amp;gt;[^\"]+)"
| eval zippedfields = mvzip(importo,tipologiaOperazione)
| mvexpand zippedfields
| rex field=zippedfields "(?&amp;lt;importo&amp;gt;[^\,]+)\,(?P&amp;lt;tipologiaOperazione&amp;gt;.*)"
| fields - zippedfields
| stats sum(importo) by tipologiaOperazione
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since there are multiple importos and tipologiaOperaziones in each log, you'll need to use &lt;CODE&gt;mvexpand&lt;/CODE&gt; to make sure all the importos are accounted for before summing them together. &lt;/P&gt;

&lt;P&gt;If you run into any problems, or the solution doesn't work for you, let me know and I'll do my best to further assist! &lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2019 00:49:44 GMT</pubDate>
    <dc:creator>rbechtold</dc:creator>
    <dc:date>2019-07-18T00:49:44Z</dc:date>
    <item>
      <title>sum multiple value in a json</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/sum-multiple-value-in-a-json/m-p/390717#M69882</link>
      <description>&lt;P&gt;Hello, I have a raw like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.success [{"importo":2,"tipologiaOperazione":"AAA"},{"importo":1.82,"tipologiaOperazione":"BBB"}, {"importo":1,"tipologiaOperazione":"AAA"}]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to have the sum of importo, by tipologiaOperazione, in this case, the result will be:&lt;/P&gt;

&lt;P&gt;AAA: 3&lt;BR /&gt;
BBB: 1.82&lt;/P&gt;

&lt;P&gt;How can I do that?&lt;/P&gt;

&lt;P&gt;I tried with this regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex max_match=100000 "(?ms)(?P&amp;lt;importoDistinta&amp;gt;(?&amp;lt;=\"importo\":)(\\d*\\.?\\d*)(?=,))" | rex max_match=100000 "(?ms)(?P&amp;lt;tipologiaOperazione&amp;gt;(?&amp;lt;=\"tipologiaOperazione\":\")(\\w*\\s*\\w*\\w*\\s*\\w*)(?=\",))" | stats sum(importoDistinta) by tipologiaOperazione
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but I've got this result:&lt;/P&gt;

&lt;P&gt;AAA: 4.82&lt;BR /&gt;
BBB: 4.82&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 13:08:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/sum-multiple-value-in-a-json/m-p/390717#M69882</guid>
      <dc:creator>3vi</dc:creator>
      <dc:date>2019-07-17T13:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple value in a json</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/sum-multiple-value-in-a-json/m-p/390718#M69883</link>
      <description>&lt;P&gt;Hey 3vi,&lt;/P&gt;

&lt;P&gt;Using the raw data you provided, I've created a search that should give you the correct numbers you're looking for (you can copy and paste this into any Splunk instance):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval _raw =  ".success [{\"importo\":2,\"tipologiaOperazione\":\"AAA\"},{\"importo\":1.82,\"tipologiaOperazione\":\"BBB\"}, {\"importo\":1,\"tipologiaOperazione\":\"AAA\"}]"
| rex field=_raw max_match=0 "\"importo\"\:(?&amp;lt;importo&amp;gt;[^\,]+)\,\"tipologiaOperazione\"\:\"(?&amp;lt;tipologiaOperazione&amp;gt;[^\"]+)"
| eval zippedfields = mvzip(importo,tipologiaOperazione)
| mvexpand zippedfields
| rex field=zippedfields "(?&amp;lt;importo&amp;gt;[^\,]+)\,(?P&amp;lt;tipologiaOperazione&amp;gt;.*)"
| fields - zippedfields
| stats sum(importo) by tipologiaOperazione
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since there are multiple importos and tipologiaOperaziones in each log, you'll need to use &lt;CODE&gt;mvexpand&lt;/CODE&gt; to make sure all the importos are accounted for before summing them together. &lt;/P&gt;

&lt;P&gt;If you run into any problems, or the solution doesn't work for you, let me know and I'll do my best to further assist! &lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 00:49:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/sum-multiple-value-in-a-json/m-p/390718#M69883</guid>
      <dc:creator>rbechtold</dc:creator>
      <dc:date>2019-07-18T00:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: sum multiple value in a json</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/sum-multiple-value-in-a-json/m-p/390719#M69884</link>
      <description>&lt;P&gt;Many thanks! it works well&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2019 09:34:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/sum-multiple-value-in-a-json/m-p/390719#M69884</guid>
      <dc:creator>3vi</dc:creator>
      <dc:date>2019-07-18T09:34:38Z</dc:date>
    </item>
  </channel>
</rss>

