<?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 Extract value from JSON array of objects in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-value-from-JSON-array-of-objects/m-p/177222#M50928</link>
    <description>&lt;P&gt;I have a JSON object that has an array inside of it.  The array is a list of objects, not just a list of values.  See below for an example.&lt;/P&gt;

&lt;P&gt;I want to extract the 'duration' field for each event when the name is 'responseTime'.  Does anyone know how to do that?  I can also assume that it's always going to be the 2nd entry in the list, so if I could do something like Timings[1] that would work.  I can't seem to get spath to work because I'm looking for an item within an array. &lt;/P&gt;

&lt;P&gt;In the end, I would like to do something like graph/table the duration of the 'providerTime' and the 'responseTime'&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE&gt;{
    Timings: [ 
      { 
         duration:  218 
         name:  providerTime
      } 
      { 
         duration:  204 
         name:  responseTime
      } 
    ] 
 }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Tue, 18 Aug 2015 17:53:30 GMT</pubDate>
    <dc:creator>AlexMcDuffMille</dc:creator>
    <dc:date>2015-08-18T17:53:30Z</dc:date>
    <item>
      <title>Extract value from JSON array of objects</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-value-from-JSON-array-of-objects/m-p/177222#M50928</link>
      <description>&lt;P&gt;I have a JSON object that has an array inside of it.  The array is a list of objects, not just a list of values.  See below for an example.&lt;/P&gt;

&lt;P&gt;I want to extract the 'duration' field for each event when the name is 'responseTime'.  Does anyone know how to do that?  I can also assume that it's always going to be the 2nd entry in the list, so if I could do something like Timings[1] that would work.  I can't seem to get spath to work because I'm looking for an item within an array. &lt;/P&gt;

&lt;P&gt;In the end, I would like to do something like graph/table the duration of the 'providerTime' and the 'responseTime'&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE&gt;{
    Timings: [ 
      { 
         duration:  218 
         name:  providerTime
      } 
      { 
         duration:  204 
         name:  responseTime
      } 
    ] 
 }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 18 Aug 2015 17:53:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-value-from-JSON-array-of-objects/m-p/177222#M50928</guid>
      <dc:creator>AlexMcDuffMille</dc:creator>
      <dc:date>2015-08-18T17:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extract value from JSON array of objects</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-value-from-JSON-array-of-objects/m-p/177223#M50929</link>
      <description>&lt;P&gt;My answer will assume following&lt;BR /&gt;
1) The data is ingested as proper JSON and you should be seeing multivalued field for your array elements (KV_MODE = json)&lt;BR /&gt;
2) As you said, responseTime is the 2nd element in and it appears only one.&lt;/P&gt;

&lt;P&gt;So try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search  | table Timings{}.* | eval temp=mvzip('Timings{}.duration','Timings{}.name',"##") | eval ResponseTime=mvindex(split(mvfilter(match(temp,".*##responseTime")),"##"),0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Aug 2015 22:17:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-value-from-JSON-array-of-objects/m-p/177223#M50929</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-08-18T22:17:41Z</dc:date>
    </item>
  </channel>
</rss>

