<?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: Multiple key value pair extractions in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Multiple-key-value-pair-extractions/m-p/72492#M14792</link>
    <description>&lt;P&gt;I just had to deal with a similar issue for Json data. I am running 4.2 and do not have the spath() available this is what I did:&lt;/P&gt;

&lt;P&gt;Initial search :&lt;/P&gt;

&lt;P&gt;BesRttSorterImpl&lt;/P&gt;

&lt;P&gt;result=&lt;BR /&gt;
[2012-02-10 14:31:12 PST] &lt;XXXX&gt; BesRttSorterImpl - DEBUG: RTT Site scores={"AAA":39.88540275,"BBB":65.32070525,"CCC":148.4583085}&lt;/XXXX&gt;&lt;/P&gt;

&lt;P&gt;First thing to pay attention is that json always returns a structure field, in this case scores is the main field.  So first addintion to the search is ignore any results without scores&lt;/P&gt;

&lt;P&gt;Search 1:BesRttSorterImpl scores&lt;/P&gt;

&lt;P&gt;The overall goal now, is to have each value pair show as a field, in this case called multi-valued  field, also used as “mv”. In order to do that,  we execute what splunk does best, remove what we do not want to see. &lt;/P&gt;

&lt;P&gt;scores={"AAA":39.88540275,"BBB":65.32070525,"CCC":148.4583085}&lt;/P&gt;

&lt;P&gt;We will use the function eval for that. What to know about eval, it executes functions and returns to another field,&lt;/P&gt;

&lt;P&gt;So it works some what like this:&lt;/P&gt;

&lt;P&gt;Search | eval result=function (X,Y)&lt;/P&gt;

&lt;P&gt;For start we will replace {“ with blank to a field called results&lt;/P&gt;

&lt;P&gt;| eval result=replace(scores,"{\"","")&lt;/P&gt;

&lt;P&gt;Note the use of \ to mean the value of “ instead of using quote as a delimiter&lt;/P&gt;

&lt;P&gt;Then we will remove the other }&lt;/P&gt;

&lt;P&gt;| eval result2=replace(result,"}","")&lt;/P&gt;

&lt;P&gt;We will now remove all “ from the results&lt;/P&gt;

&lt;P&gt;| eval result3=replace(result2,"\"","")&lt;/P&gt;

&lt;P&gt;Now we replace the Json delimiter with “=” &lt;/P&gt;

&lt;P&gt;| eval result4=replace(result3,":","=")&lt;/P&gt;

&lt;P&gt;Final step is t make subfields using split&lt;/P&gt;

&lt;P&gt;| eval result5=split(result4,",")&lt;/P&gt;

&lt;P&gt;Now we have all the values in result5, to be present then we use table.&lt;/P&gt;

&lt;P&gt;Table result5&lt;/P&gt;

&lt;P&gt;Putting all together:&lt;/P&gt;

&lt;P&gt;BesRttSorterImpl scores | eval result=replace(scores,"{\"","") | eval result2=replace(result,"}","") | eval result3=replace(result2,"\"","") | eval result4=replace(result3,":","=") | eval result5=split(result4,",") | table result5&lt;/P&gt;

&lt;P&gt;will show:&lt;BR /&gt;
AAA=value&lt;BR /&gt;
BBB=Value&lt;BR /&gt;
CCC=Value&lt;/P&gt;

&lt;P&gt;If the elements are not in the order you want, then Further manipulation is required to have all element match Using If() and Match() can do that.&lt;/P&gt;

&lt;P&gt;Not elegant, but worked for me.&lt;/P&gt;</description>
    <pubDate>Sat, 11 Feb 2012 01:03:09 GMT</pubDate>
    <dc:creator>borisalves</dc:creator>
    <dc:date>2012-02-11T01:03:09Z</dc:date>
    <item>
      <title>Multiple key value pair extractions</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Multiple-key-value-pair-extractions/m-p/72491#M14791</link>
      <description>&lt;P&gt;I have a logfile with the following format:&lt;/P&gt;

&lt;P&gt;&lt;DATE&gt; LOG: &lt;KEY1&gt;: &lt;VALUE1&gt;; &lt;KEY2&gt;: &lt;VALUE2&gt;; .....&lt;/VALUE2&gt;&lt;/KEY2&gt;&lt;/VALUE1&gt;&lt;/KEY1&gt;&lt;/DATE&gt;&lt;/P&gt;

&lt;P&gt;If I had only one key value pair I think could do&lt;/P&gt;

&lt;P&gt;[mylog]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
REGEX = LOG: (\S+): (.*);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
Format = $1::$2&lt;/P&gt;

&lt;P&gt;or two pairs&lt;/P&gt;

&lt;P&gt;[mylog]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
REGEX = LOG: (\S+): (.&lt;EM&gt;); (\S+): (.&lt;/EM&gt;); &lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
Format = $1::$2 $3::$4&lt;/P&gt;

&lt;P&gt;but what can I do if I have an unknown number of pairs ?&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;
Markus&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2011 14:55:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Multiple-key-value-pair-extractions/m-p/72491#M14791</guid>
      <dc:creator>huaraz</dc:creator>
      <dc:date>2011-09-09T14:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple key value pair extractions</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Multiple-key-value-pair-extractions/m-p/72492#M14792</link>
      <description>&lt;P&gt;I just had to deal with a similar issue for Json data. I am running 4.2 and do not have the spath() available this is what I did:&lt;/P&gt;

&lt;P&gt;Initial search :&lt;/P&gt;

&lt;P&gt;BesRttSorterImpl&lt;/P&gt;

&lt;P&gt;result=&lt;BR /&gt;
[2012-02-10 14:31:12 PST] &lt;XXXX&gt; BesRttSorterImpl - DEBUG: RTT Site scores={"AAA":39.88540275,"BBB":65.32070525,"CCC":148.4583085}&lt;/XXXX&gt;&lt;/P&gt;

&lt;P&gt;First thing to pay attention is that json always returns a structure field, in this case scores is the main field.  So first addintion to the search is ignore any results without scores&lt;/P&gt;

&lt;P&gt;Search 1:BesRttSorterImpl scores&lt;/P&gt;

&lt;P&gt;The overall goal now, is to have each value pair show as a field, in this case called multi-valued  field, also used as “mv”. In order to do that,  we execute what splunk does best, remove what we do not want to see. &lt;/P&gt;

&lt;P&gt;scores={"AAA":39.88540275,"BBB":65.32070525,"CCC":148.4583085}&lt;/P&gt;

&lt;P&gt;We will use the function eval for that. What to know about eval, it executes functions and returns to another field,&lt;/P&gt;

&lt;P&gt;So it works some what like this:&lt;/P&gt;

&lt;P&gt;Search | eval result=function (X,Y)&lt;/P&gt;

&lt;P&gt;For start we will replace {“ with blank to a field called results&lt;/P&gt;

&lt;P&gt;| eval result=replace(scores,"{\"","")&lt;/P&gt;

&lt;P&gt;Note the use of \ to mean the value of “ instead of using quote as a delimiter&lt;/P&gt;

&lt;P&gt;Then we will remove the other }&lt;/P&gt;

&lt;P&gt;| eval result2=replace(result,"}","")&lt;/P&gt;

&lt;P&gt;We will now remove all “ from the results&lt;/P&gt;

&lt;P&gt;| eval result3=replace(result2,"\"","")&lt;/P&gt;

&lt;P&gt;Now we replace the Json delimiter with “=” &lt;/P&gt;

&lt;P&gt;| eval result4=replace(result3,":","=")&lt;/P&gt;

&lt;P&gt;Final step is t make subfields using split&lt;/P&gt;

&lt;P&gt;| eval result5=split(result4,",")&lt;/P&gt;

&lt;P&gt;Now we have all the values in result5, to be present then we use table.&lt;/P&gt;

&lt;P&gt;Table result5&lt;/P&gt;

&lt;P&gt;Putting all together:&lt;/P&gt;

&lt;P&gt;BesRttSorterImpl scores | eval result=replace(scores,"{\"","") | eval result2=replace(result,"}","") | eval result3=replace(result2,"\"","") | eval result4=replace(result3,":","=") | eval result5=split(result4,",") | table result5&lt;/P&gt;

&lt;P&gt;will show:&lt;BR /&gt;
AAA=value&lt;BR /&gt;
BBB=Value&lt;BR /&gt;
CCC=Value&lt;/P&gt;

&lt;P&gt;If the elements are not in the order you want, then Further manipulation is required to have all element match Using If() and Match() can do that.&lt;/P&gt;

&lt;P&gt;Not elegant, but worked for me.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Feb 2012 01:03:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Multiple-key-value-pair-extractions/m-p/72492#M14792</guid>
      <dc:creator>borisalves</dc:creator>
      <dc:date>2012-02-11T01:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple key value pair extractions</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Multiple-key-value-pair-extractions/m-p/72493#M14793</link>
      <description>&lt;P&gt;Have you looked at DELIMS rather than REGEX?&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Createandmaintainsearch-timefieldextractionsthroughconfigurationfiles#Configuring_delimiter-based_field_extraction" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Createandmaintainsearch-timefieldextractionsthroughconfigurationfiles#Configuring_delimiter-based_field_extraction&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Not sure how that would cope with the LOG at the start of the line, but I imagine you could always strip it off before DELIMS. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:23:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Multiple-key-value-pair-extractions/m-p/72493#M14793</guid>
      <dc:creator>willthames2</dc:creator>
      <dc:date>2020-09-28T11:23:29Z</dc:date>
    </item>
  </channel>
</rss>

