<?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: extract count of name value pairs from a json in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679281#M232212</link>
    <description>&lt;LI-CODE lang="markup"&gt;| makeresults | eval _raw="{
	\"timeStamp\": \"2024-02-29T10:00:00.673Z\",
	\"collectionIntervalInMinutes\": \"1\",
	\"node\": \"plgiasrtfing001\",
	\"inboundErrorSummary\": [
		{
			\"name\": \"400BadRequestMalformedHeader\",
			\"value\": 1
		},
		{
			\"name\": \"501NotImplementedMethod\",
			\"value\": 2
		},
		{
			\"name\": \"otherErrorResponses\",
			\"value\": 1
		}
	]
}|
{
	\"timeStamp\": \"2024-02-29T10:00:00.674Z\",
	\"collectionIntervalInMinutes\": \"1\",
	\"node\": \"plgiasrtfing001\",
	\"inboundErrorSummary\": [
		{
			\"name\": \"400BadRequestMalformedHeader\",
			\"value\": 10
		},
		{
			\"name\": \"501NotImplementedMethod\",
			\"value\": 5
		},
		{
			\"name\": \"otherErrorResponses\",
			\"value\": 6
		}
	]
}"
| makemv _raw delim="|"
| rename _raw as raw
| mvexpand raw
| rex field=raw "timeStamp\"\: \"(?&amp;lt;_time&amp;gt;[^\"]+)"
| rename raw as _raw
```Below is the SPL you need potentially```
| spath inboundErrorSummary{}
| mvexpand  inboundErrorSummary{}
| spath input=inboundErrorSummary{}
| chart values(value) over _time by name&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 01 Mar 2024 13:59:57 GMT</pubDate>
    <dc:creator>thambisetty</dc:creator>
    <dc:date>2024-03-01T13:59:57Z</dc:date>
    <item>
      <title>extract count of name value pairs from a json</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679260#M232206</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; I have multiple events with the following JSON object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
	"timeStamp": "2024-02-29T10:00:00.673Z",
	"collectionIntervalInMinutes": "1",
	"node": "plgiasrtfing001",
	"inboundErrorSummary": [
		{
			"name": "400BadRequestMalformedHeader",
			"value": 1
		},
		{
			"name": "501NotImplementedMethod",
			"value": 2
		},
		{
			"name": "otherErrorResponses",
			"value": 1
		}
	]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to extract the name/values from the&amp;nbsp;inboundErrorSummary array and display the sum total of all the values of the same name and plot them by time.&lt;/P&gt;&lt;P&gt;So the output should be something like&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="25%"&gt;Date&lt;/TD&gt;&lt;TD width="25%"&gt;400BadRequestMalformedHeader&lt;/TD&gt;&lt;TD width="25%"&gt;501NotImplementedMethod&lt;/TD&gt;&lt;TD width="25%"&gt;otherErrorResponses&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;2024-02-29T10:00:00&lt;/TD&gt;&lt;TD width="25%"&gt;1&lt;/TD&gt;&lt;TD width="25%"&gt;2&lt;/TD&gt;&lt;TD width="25%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="25%"&gt;2024-02-29T11:00:00&lt;/TD&gt;&lt;TD width="25%"&gt;10&lt;/TD&gt;&lt;TD width="25%"&gt;40&lt;/TD&gt;&lt;TD width="25%"&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even a total count of each name field should also work. I am quite new to splunk queries, so hope someone can help and also explain the steps on how its done.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 10:34:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679260#M232206</guid>
      <dc:creator>mhdzabi</dc:creator>
      <dc:date>2024-03-01T10:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: extract count of name value pairs from a json</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679264#M232208</link>
      <description>&lt;P&gt;Argh. That's ugly data.&lt;/P&gt;&lt;P&gt;You need to firstly extract the array part&lt;/P&gt;&lt;PRE&gt;| spath inboundErrorSummary{}&lt;/PRE&gt;&lt;P&gt;Then you have to split it into separate rows&lt;/P&gt;&lt;PRE&gt;| mvexpand inboundErrorSummary{}&lt;/PRE&gt;&lt;P&gt;And then you have to parse the json again&lt;/P&gt;&lt;PRE&gt;| spath input=inboundErrorSummary{}&lt;/PRE&gt;&lt;P&gt;At this point you'll have separate fields called "name" and "value" at each result row and you'll be able to do stats/chart/timechart/whatever you want with it.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 11:25:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679264#M232208</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-03-01T11:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: extract count of name value pairs from a json</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679281#M232212</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults | eval _raw="{
	\"timeStamp\": \"2024-02-29T10:00:00.673Z\",
	\"collectionIntervalInMinutes\": \"1\",
	\"node\": \"plgiasrtfing001\",
	\"inboundErrorSummary\": [
		{
			\"name\": \"400BadRequestMalformedHeader\",
			\"value\": 1
		},
		{
			\"name\": \"501NotImplementedMethod\",
			\"value\": 2
		},
		{
			\"name\": \"otherErrorResponses\",
			\"value\": 1
		}
	]
}|
{
	\"timeStamp\": \"2024-02-29T10:00:00.674Z\",
	\"collectionIntervalInMinutes\": \"1\",
	\"node\": \"plgiasrtfing001\",
	\"inboundErrorSummary\": [
		{
			\"name\": \"400BadRequestMalformedHeader\",
			\"value\": 10
		},
		{
			\"name\": \"501NotImplementedMethod\",
			\"value\": 5
		},
		{
			\"name\": \"otherErrorResponses\",
			\"value\": 6
		}
	]
}"
| makemv _raw delim="|"
| rename _raw as raw
| mvexpand raw
| rex field=raw "timeStamp\"\: \"(?&amp;lt;_time&amp;gt;[^\"]+)"
| rename raw as _raw
```Below is the SPL you need potentially```
| spath inboundErrorSummary{}
| mvexpand  inboundErrorSummary{}
| spath input=inboundErrorSummary{}
| chart values(value) over _time by name&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 01 Mar 2024 13:59:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679281#M232212</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2024-03-01T13:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: extract count of name value pairs from a json</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679343#M232229</link>
      <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/129407"&gt;@thambisetty&lt;/a&gt;&amp;nbsp;meant to use sum instead of values. &amp;nbsp;Also, your seem to desire result be bucketed by hour aligned at the beginning of a calendar hour. &amp;nbsp;If so, you also need a bin command.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;```Below is the SPL you need potentially```
| spath inboundErrorSummary{}
| mvexpand  inboundErrorSummary{}
| spath input=inboundErrorSummary{}
| bin _time span=1h@h
| chart sum(value) over _time by name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I recently learned &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Fromjson" target="_blank" rel="noopener"&gt;fromjson&lt;/A&gt; command introduced in Splunk 9. &amp;nbsp;It makes SPL somewhat easier to read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| fromjson _raw
| mvexpand inboundErrorSummary
| spath input=inboundErrorSummary
| timechart span=1h@h sum(value) by name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here, timechart is equivalent to&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/129407"&gt;@thambisetty&lt;/a&gt;'s chart but you do not have to enter a separate bin command.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 21:07:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extract-count-of-name-value-pairs-from-a-json/m-p/679343#M232229</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-03-01T21:07:07Z</dc:date>
    </item>
  </channel>
</rss>

