<?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 you parse and chart fields in a JSON array? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416418#M73572</link>
    <description>&lt;P&gt;@someone4321 ,&lt;BR /&gt;
Ofcourse it helps. You have a multivalue field and we need to extract them. So try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="myHost" sourcetype=mySourceType "My log: " 
 | spath input=myMetrics
|eval x=mvzip('{}.counter','{}.fieldName',"#")|mvexpand x
|rex field=x "(?&amp;lt;counter&amp;gt;\d+)#(?&amp;lt;fieldName&amp;gt;\w+)"|timechart span=1h sum(counter) by fieldName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Jan 2019 04:04:36 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2019-01-24T04:04:36Z</dc:date>
    <item>
      <title>How do you parse and chart fields in a JSON array?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416413#M73567</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;I have a log event where part of the log entry contains some JSON data similar to the following format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    [
        {
            "fieldName": "value1",
            "counter": 4
        },
        {
            "fieldName": "value2",
            "counter": 2
        },
        {
            "fieldName": "value3",
            "counter": 13
        }
    ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gets outputted periodically and each log &lt;STRONG&gt;may&lt;/STRONG&gt; have the same fieldName values. I have a field extraction to parse the JSON part into a field &lt;EM&gt;myMetrics&lt;/EM&gt;. I now need to sum the &lt;EM&gt;counter&lt;/EM&gt; over a given period of time BY &lt;EM&gt;fieldName&lt;/EM&gt; and then chart it. So far I have the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="myHost" sourcetype=mySourceType "My log: " | spath input=myMetrics | timechart span=1h sum({}.counter) by {}.fieldName
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This partially works and is given me the following result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time                          value1    value2    value3
2019-01-01T01:00:00.000-0800   19        19        19
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It seems to be summing all the values and not by &lt;EM&gt;fieldName&lt;/EM&gt;. &lt;/P&gt;

&lt;P&gt;How can I fix this?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 00:05:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416413#M73567</guid>
      <dc:creator>someone4321</dc:creator>
      <dc:date>2019-01-22T00:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do you parse and chart fields in a JSON array?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416414#M73568</link>
      <description>&lt;P&gt;@someone4321 ,&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Updated as per comments:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults|eval json=     "[
         {
             \"fieldName\": \"value1\",
             \"counter\": 4
         },
         {
             \"fieldName\": \"value2\",
             \"counter\": 2
         },
         {
             \"fieldName\": \"value3\",
             \"counter\": 13
         }
     ]"
     |spath input=json|eval x=mvzip('{}.counter','{}.fieldName',"#")|mvexpand x
     |rex field=x "(?&amp;lt;counter&amp;gt;\d+)#(?&amp;lt;fieldName&amp;gt;\w+)"
     |timechart span=1h sum(counter) by fieldName
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try enclosing the field names in single quote (')&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     index="myIndex" host="myHost" sourcetype=mySourceType "My log: " | spath input=myMetrics 
   | timechart span=1h sum('{}.counter') by '{}.fieldName'
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jan 2019 05:38:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416414#M73568</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-01-22T05:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do you parse and chart fields in a JSON array?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416415#M73569</link>
      <description>&lt;P&gt;@renjith.nair  No luck, adding quotes resulted in zero results found.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2019 12:57:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416415#M73569</guid>
      <dc:creator>someone4321</dc:creator>
      <dc:date>2019-01-22T12:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do you parse and chart fields in a JSON array?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416416#M73570</link>
      <description>&lt;P&gt;Ok, are you able to see the results for this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="myHost" sourcetype=mySourceType "My log: " | spath input=myMetrics|table {}.counter,{}.fieldName
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If yes , can you try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="myHost" sourcetype=mySourceType "My log: " 
| spath input=myMetrics|rename {}.counter as counter,{}.fieldName as fieldName
|timechart span=1h sum(counter) by fieldName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Jan 2019 04:10:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416416#M73570</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-01-23T04:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do you parse and chart fields in a JSON array?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416417#M73571</link>
      <description>&lt;P&gt;Unfortunately I tried that already and it produces the same results as I got originally. That is, for the original example, I still get all the distinct fieldNames showing the total sum count:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; _time                          value1    value2    value3
 2019-01-01T01:00:00.000-0800   19        19        19
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The table you suggested works but what is perhaps interesting, is if I try to put the values in a table as you suggested, each unique fieldName is not given it own distinct row as I would have thought. It just appears as a single row in the table with unique values given new lines within the row. They do line up with the correct counter values however. But maybe that's a hint?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jan 2019 14:21:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416417#M73571</guid>
      <dc:creator>someone4321</dc:creator>
      <dc:date>2019-01-23T14:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do you parse and chart fields in a JSON array?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416418#M73572</link>
      <description>&lt;P&gt;@someone4321 ,&lt;BR /&gt;
Ofcourse it helps. You have a multivalue field and we need to extract them. So try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" host="myHost" sourcetype=mySourceType "My log: " 
 | spath input=myMetrics
|eval x=mvzip('{}.counter','{}.fieldName',"#")|mvexpand x
|rex field=x "(?&amp;lt;counter&amp;gt;\d+)#(?&amp;lt;fieldName&amp;gt;\w+)"|timechart span=1h sum(counter) by fieldName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Jan 2019 04:04:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416418#M73572</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-01-24T04:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do you parse and chart fields in a JSON array?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416419#M73573</link>
      <description>&lt;P&gt;That worked, thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jan 2019 16:40:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416419#M73573</guid>
      <dc:creator>someone4321</dc:creator>
      <dc:date>2019-01-24T16:40:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do you parse and chart fields in a JSON array?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416420#M73574</link>
      <description>&lt;P&gt;@someone4321 ,glad to know, Had updated the answer with the suggestion. If you dont have further question on that, please accept as answer to close the thread.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jan 2019 03:15:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-you-parse-and-chart-fields-in-a-JSON-array/m-p/416420#M73574</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-01-25T03:15:07Z</dc:date>
    </item>
  </channel>
</rss>

