<?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 data from JSON array in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-data-from-JSON-array/m-p/410333#M118367</link>
    <description>&lt;P&gt;I have some data which is along the following format;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"event":
     {
     "Timestamp":"2019-01-16 22:20:26.123"
     "Stream":"123456",
     "Id":"789",
     "Data": [
         {
        "name":"0",
            "rank":"1",
            "score":"34.56787"
         },
         {
        "name":"1",
            "rank":"3",
            "score":"4.74287"
         },
         {
        "name":"2",
            "rank":"2",
            "score":"12.54863"
         },
         {
        "name":"3",
            "rank":"4",
            "score":"1.78916"
         },

     ]
     }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We get around 800,000 of these per day and have around 50 data elements in each one.&lt;/P&gt;

&lt;P&gt;I am trying to find the best way to return the top 2 rank name and score for each event, e.g.;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1_name = 0
1_score = 34.56787
2_name = 2
2_score = 12.54863
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And another search to timechart all &lt;STRONG&gt;scores&lt;/STRONG&gt; by &lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jan 2019 22:42:27 GMT</pubDate>
    <dc:creator>karlbosanquet</dc:creator>
    <dc:date>2019-01-16T22:42:27Z</dc:date>
    <item>
      <title>Extract data from JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-data-from-JSON-array/m-p/410333#M118367</link>
      <description>&lt;P&gt;I have some data which is along the following format;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"event":
     {
     "Timestamp":"2019-01-16 22:20:26.123"
     "Stream":"123456",
     "Id":"789",
     "Data": [
         {
        "name":"0",
            "rank":"1",
            "score":"34.56787"
         },
         {
        "name":"1",
            "rank":"3",
            "score":"4.74287"
         },
         {
        "name":"2",
            "rank":"2",
            "score":"12.54863"
         },
         {
        "name":"3",
            "rank":"4",
            "score":"1.78916"
         },

     ]
     }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We get around 800,000 of these per day and have around 50 data elements in each one.&lt;/P&gt;

&lt;P&gt;I am trying to find the best way to return the top 2 rank name and score for each event, e.g.;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1_name = 0
1_score = 34.56787
2_name = 2
2_score = 12.54863
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And another search to timechart all &lt;STRONG&gt;scores&lt;/STRONG&gt; by &lt;STRONG&gt;name&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 22:42:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-data-from-JSON-array/m-p/410333#M118367</guid>
      <dc:creator>karlbosanquet</dc:creator>
      <dc:date>2019-01-16T22:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-data-from-JSON-array/m-p/410334#M118368</link>
      <description>&lt;P&gt;Expected output examples;&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Search 1 (table timestamp Stream Id 1_name 1_value 2_name 2_value)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;||Timestamp||Stream||Id||1_name||1_score||2_name||2_score||&lt;BR /&gt;
|2019-01-16 22:20:26.123|123456|789|0|34.56787|2|12.54863|&lt;BR /&gt;
|2019-01-16 22:21:28.567|123456|790|12|54.78797|46|34.82632|&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Search 2 (timechart values(score) by name)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;||Timestamp||0||1||2||3||4||5||&lt;BR /&gt;
|2019-01-16 22:20:26.123|34.56787|4.74287|12.54863|1.78916|3.35732|&lt;BR /&gt;
|2019-01-15 12:21:34.244|2.34689|12.45211|21.24852|14.72412|2.28342|&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:48:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-data-from-JSON-array/m-p/410334#M118368</guid>
      <dc:creator>karlbosanquet</dc:creator>
      <dc:date>2020-09-29T22:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Extract data from JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-data-from-JSON-array/m-p/410335#M118369</link>
      <description>&lt;P&gt;Hi Can you try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw = "{\"event\":
      {
      \"Timestamp\":\"2019-01-16 22:20:26.123\",
      \"Stream\":\"123456\",
      \"Id\":\"789\",
      \"Data\": [
          {
         \"name\":\"0\",
             \"rank\":\"1\",
             \"score\":\"34.56787\"
                  },
          {
         \"name\":\"1\",
             \"rank\":\"3\",
             \"score\":\"4.74287\"
                  },
          {
         \"name\":\"2\",
             \"rank\":\"2\",
             \"score\":\"12.54863\"
                  },
          {
         \"name\":\"3\",
             \"rank\":\"4\",
             \"score\":\"1.78916\"
                  },

      ]
      }
 }" 
| spath 
| rename event.Data{}.* as * event.Timestamp as Timestamp event.Id as Id event.Stream as Stream 
| eval data=mvzip(mvzip(name,rank),score) 
| mvexpand data 
| rex field=data "(?&amp;lt;name&amp;gt;[^\,]+)\,(?&amp;lt;rank&amp;gt;[^\,]+)\,(?&amp;lt;score&amp;gt;.*)" 
| table Timestamp Stream Id name rank score
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also try this for top 2 scores:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|stats values(score) as score by rank name 
|  sort 2 -score
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2019 08:55:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-data-from-JSON-array/m-p/410335#M118369</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-01-17T08:55:43Z</dc:date>
    </item>
  </channel>
</rss>

