<?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: Pulling a multivalue field from a JSON array in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331923#M61483</link>
    <description>&lt;P&gt;Give this a try (everything before &lt;CODE&gt;spath&lt;/CODE&gt; is to generate sample data, replace it with your base search)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="{
\"SERVICES\": [
{
  \"HTTPStatus\":\"200\",  \"ServRespCode\":\"Success\",  \"ServRespTime\":\"1200\",  \"ServRespCached\":\"Y\",  \"ServiceShortName\":\"Service1\",   \"DataSource\":\"Source1\",   \"ServiceURI\":\"Service1Url\"
   },
   {
   \"HTTPStatus\":\"200\",   \"ServRespCode\":\"Success\",   \"ServRespTime\":\"1200\",   \"ServRespCached\":\"Y\",   \"ServiceShortName\":\"Service2\",  \"DataSource\":\"Service2Source\",
   \"ServiceURI\":\"Service2URL\"
   },
   {
   \"HTTPStatus\":\"200\",   \"ServRespCode\":\"Success\",   \"ServRespTime\":\"12\",   \"ServRespCached\":\"Y\",   \"ServiceShortName\":\"Service3\",   \"DataSource\":\"Service3Source\",
   \"ServiceURI\":\"Service3URL\"
   }
 ]
 }
" 
| spath | rename SERVICES{}.* as *| eval temp=mvzip(HTTPStatus,mvzip(ServRespCode,mvzip(ServRespTime,mvzip(ServiceShortName,mvzip(DataSource,ServiceURI,"#"),"#"),"#"),"#"),"#")| mvexpand temp | rex field=temp "(?&amp;lt;HTTPStatus&amp;gt;.+)#(?&amp;lt;ServRespCode&amp;gt;.+)#(?&amp;lt;ServRespTime&amp;gt;.+)#(?&amp;lt;ServiceShortName&amp;gt;.+)#(?&amp;lt;DataSource&amp;gt;.+)#(?&amp;lt;ServiceURI&amp;gt;.+)" | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Jan 2018 21:42:01 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-01-23T21:42:01Z</dc:date>
    <item>
      <title>Pulling a multivalue field from a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331920#M61480</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to pull a multivalue field from a JSON array to get statistics from it. The data looks as follows: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"APIHEADERRESPONSE":{...specific information...
    },
"SERVICES": [
  {
    "HTTPStatus":"200",
    "ServRespCode":"Success",
    "ServRespTime":"1200",
    "ServRespCached":"Y",
    "ServiceShortName":"Service1",
    "DataSource":"Source1",
    "ServiceURI":"Service1Url"
    },
    {
    "HTTPStatus":"200",
    "ServRespCode":"Success",
    "ServRespTime":"1200",
    "ServRespCached":"Y",
    "ServiceShortName":"Service2",
    "DataSource":"Service2Source",
    "ServiceURI":"Service2URL"
    },
    {
    "HTTPStatus":"200",
    "ServRespCode":"Success",
    "ServRespTime":"12",
    "ServRespCached":"Y",
    "ServiceShortName":"Service3",
    "DataSource":"Service3Source",
    "ServiceURI":"Service3URL"
    }
  ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Our data follows the structure of an initial block of identifying information, followed by specific details of further backend calls our APIs make. We are printing the results of those backend calls into an array in the JSON (services block) we print out to splunk.&lt;/P&gt;

&lt;P&gt;However,  it is not a standardized amount of elements within the array. We can have 1 to many different services printed, and it varies from event to event. Further, the order is not normalized either, so we have no idea which service will print first.&lt;/P&gt;

&lt;P&gt;Is there a way for us to extract the details of a specific service without using regex? If we had multiple events, how would I get something like the median response time of service1? Is there a way we can use SPATH to get this information without relying on the expensive nature of regex?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 18:58:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331920#M61480</guid>
      <dc:creator>brajaram</dc:creator>
      <dc:date>2018-01-23T18:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling a multivalue field from a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331921#M61481</link>
      <description>&lt;P&gt;With just the base search ran on Smart Mode, what all fields do you see(either on the left field sidebar OR by adding &lt;CODE&gt;| fieldsummary&lt;/CODE&gt; in your base search)??&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 20:02:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331921#M61481</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-01-23T20:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling a multivalue field from a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331922#M61482</link>
      <description>&lt;P&gt;I can see all of the fields inside the service array properly - they are labeled like:&lt;/P&gt;

&lt;P&gt;Services{}.DataSource&lt;BR /&gt;
Services{}.ServiceRespTime&lt;/P&gt;

&lt;P&gt;etc.&lt;/P&gt;

&lt;P&gt;Splunk is correctly identifying the fields as multivalue - it captures multiple response times and lists them all under Services{}.ServiceRespTime.&lt;/P&gt;

&lt;P&gt;However, there is nothing in the fields that seem to indicate which block each response time corresponds to.  So while it captures all the response times, I don't know how to(without using regex) get the response time of service1 specifically.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 20:15:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331922#M61482</guid>
      <dc:creator>brajaram</dc:creator>
      <dc:date>2018-01-23T20:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling a multivalue field from a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331923#M61483</link>
      <description>&lt;P&gt;Give this a try (everything before &lt;CODE&gt;spath&lt;/CODE&gt; is to generate sample data, replace it with your base search)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="{
\"SERVICES\": [
{
  \"HTTPStatus\":\"200\",  \"ServRespCode\":\"Success\",  \"ServRespTime\":\"1200\",  \"ServRespCached\":\"Y\",  \"ServiceShortName\":\"Service1\",   \"DataSource\":\"Source1\",   \"ServiceURI\":\"Service1Url\"
   },
   {
   \"HTTPStatus\":\"200\",   \"ServRespCode\":\"Success\",   \"ServRespTime\":\"1200\",   \"ServRespCached\":\"Y\",   \"ServiceShortName\":\"Service2\",  \"DataSource\":\"Service2Source\",
   \"ServiceURI\":\"Service2URL\"
   },
   {
   \"HTTPStatus\":\"200\",   \"ServRespCode\":\"Success\",   \"ServRespTime\":\"12\",   \"ServRespCached\":\"Y\",   \"ServiceShortName\":\"Service3\",   \"DataSource\":\"Service3Source\",
   \"ServiceURI\":\"Service3URL\"
   }
 ]
 }
" 
| spath | rename SERVICES{}.* as *| eval temp=mvzip(HTTPStatus,mvzip(ServRespCode,mvzip(ServRespTime,mvzip(ServiceShortName,mvzip(DataSource,ServiceURI,"#"),"#"),"#"),"#"),"#")| mvexpand temp | rex field=temp "(?&amp;lt;HTTPStatus&amp;gt;.+)#(?&amp;lt;ServRespCode&amp;gt;.+)#(?&amp;lt;ServRespTime&amp;gt;.+)#(?&amp;lt;ServiceShortName&amp;gt;.+)#(?&amp;lt;DataSource&amp;gt;.+)#(?&amp;lt;ServiceURI&amp;gt;.+)" | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jan 2018 21:42:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331923#M61483</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-01-23T21:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling a multivalue field from a JSON array</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331924#M61484</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Thanks for the response. That doesn't get quite what I need...in fact it seems to result in duplicating events? However, I was able to build off of what you gave me and various other questions(which actually led me to other answers you have given!) to get this query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; initial search  |  table SERVICES{}.* | eval respTable=mvzip('SERVICES{}.ServRespTime', 'SERVICES{}.ServiceShortName', "&amp;amp;&amp;amp;") | eval ResponseTime=mvindex(split(mvfilter(match(respTable,".*&amp;amp;&amp;amp;Service1Name")),"&amp;amp;&amp;amp;"),0) | table ResponseTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since I don't use spath, are there any concerns with the cost of using this type of query extensively?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 04:07:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Pulling-a-multivalue-field-from-a-JSON-array/m-p/331924#M61484</guid>
      <dc:creator>brajaram</dc:creator>
      <dc:date>2018-01-24T04:07:57Z</dc:date>
    </item>
  </channel>
</rss>

