<?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 pairldelim kvdelim JSON problems in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471245#M146004</link>
    <description>&lt;P&gt;@trtracy81 &lt;/P&gt;

&lt;P&gt;Can you please share your expected output from your given sample? &lt;/P&gt;

&lt;P&gt;Meanwhile you can check my answer in below post:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/777804/how-to-parse-json-with-multiple-array-to-barchart.html#answer-776828"&gt;https://answers.splunk.com/answers/777804/how-to-parse-json-with-multiple-array-to-barchart.html#answer-776828&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/777671/json-to-table.html#answer-776665"&gt;https://answers.splunk.com/answers/777671/json-to-table.html#answer-776665&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/789853/extract-fields-from-nested-multivalue-json.html#answer-789080"&gt;https://answers.splunk.com/answers/789853/extract-fields-from-nested-multivalue-json.html#answer-789080&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Feb 2020 05:09:58 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2020-02-13T05:09:58Z</dc:date>
    <item>
      <title>Extract pairldelim kvdelim JSON problems</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471244#M146003</link>
      <description>&lt;P&gt;I have JSON data that I'm trying to extract into fields and unable to get all the data extracted correctly.&lt;/P&gt;

&lt;P&gt;My query is &lt;BR /&gt;
&lt;STRONG&gt;index=myindex&lt;BR /&gt;
|spath&lt;BR /&gt;
|extract paridelim="," kvdelim=":{}[,]"&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;My data looks like this&lt;BR /&gt;
*{"version":"1.0.0","integrationType":"metric","action":"created","metrics":{"General":{"tapid":1,"port":2,"length":16,"timestamp":1580164559,"packet_id":626910,"protocol":"test","Indexes":{"Address1":[0],"FCode":[1],"AddressOut1":[2,3],"outputValue":[4,5],"checksum":[6,7]}},"ApplicationLayer":{"Rail":{"Rail16":1}},"TransportLayer":{"Address2":3,"FCode2":{"code":5,"string":"Read Single Values"},"type":"response","crc":56253}}}&lt;/P&gt;

&lt;P&gt;{"version":"1.0.0","integrationType":"metric","action":"created","metrics":{"General":{"tapid":1,"port":2,"length":30,"timestamp":1580164556,"packet_id":626904,"protocol":"test","Indexes":{"Address1":[0],"FCode":[1],"RValues":[2],"reg1":[3,4],"reg2":[5,6],"reg3":[7,8],"reg4":[9,10],"reg5":[11,12],"reg6":[13,14],"reg7":[15,16],"reg8":[17,18],"reg9":[19,20],"reg10":[21,22],"reg11":[23,24],"reg12":[25,26],"reg13":[27,28],"checksum":[29,28]}},"ApplicationLayer":{"Registering":{}},"TransportLayer":{"Address2":3,"FCode2":{"code":3,"string":"Read Multiple Values"},"type":"response","crc":18279}}}*&lt;/P&gt;

&lt;P&gt;The query does fine for most of the data but fails to get multi-values.&lt;BR /&gt;
For example:&lt;BR /&gt;
"AddressOut1":[2,3] will only give me AddressOut1 = 2   --  It's not extracting the 3.  I was expecting AddressOut1=2,3&lt;BR /&gt;
"checksum":[6,7] again will only give me checksum = 6  --  and skip the 7.&lt;BR /&gt;
The same with "reg1":[3,4].  I'm only getting the 3.  Whenever there is multiple values, I only get the first entry in the array.&lt;/P&gt;

&lt;P&gt;I suspect it because the "," is used to separate the keys but because one one of the values also uses a "," as a separator, it not able to do it.&lt;BR /&gt;
Is there a better way to extract these or am I missing something?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 17:14:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471244#M146003</guid>
      <dc:creator>trtracy81</dc:creator>
      <dc:date>2020-02-12T17:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pairldelim kvdelim JSON problems</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471245#M146004</link>
      <description>&lt;P&gt;@trtracy81 &lt;/P&gt;

&lt;P&gt;Can you please share your expected output from your given sample? &lt;/P&gt;

&lt;P&gt;Meanwhile you can check my answer in below post:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/777804/how-to-parse-json-with-multiple-array-to-barchart.html#answer-776828"&gt;https://answers.splunk.com/answers/777804/how-to-parse-json-with-multiple-array-to-barchart.html#answer-776828&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/777671/json-to-table.html#answer-776665"&gt;https://answers.splunk.com/answers/777671/json-to-table.html#answer-776665&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/789853/extract-fields-from-nested-multivalue-json.html#answer-789080"&gt;https://answers.splunk.com/answers/789853/extract-fields-from-nested-multivalue-json.html#answer-789080&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 05:09:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471245#M146004</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-02-13T05:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pairldelim kvdelim JSON problems</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471246#M146005</link>
      <description>&lt;P&gt;Hi Kamlesh.&lt;BR /&gt;
I looked at your 3 links and I did not see any of the fields that had a Key/Value pair that matches the type of data I have.  What I was hoping for was something that extracts the fields to look something like this.&lt;/P&gt;

&lt;P&gt;version         : "1.0.0"&lt;BR /&gt;
integrationType : "metric"&lt;BR /&gt;
action          : "created"&lt;BR /&gt;
tapid           : 1&lt;BR /&gt;
port            : 2&lt;BR /&gt;
length          : 16&lt;BR /&gt;
timestamp       : 1580164559&lt;BR /&gt;
packet_id       : 626910&lt;BR /&gt;
protocol        : "test"&lt;BR /&gt;
Address1        : 0&lt;BR /&gt;
FCode           : 1&lt;BR /&gt;
AddressOut1 : 2,3&lt;BR /&gt;
outputValue     : 4,5&lt;BR /&gt;
checksum        : 6,7&lt;BR /&gt;
Rail16          : 1&lt;BR /&gt;
Address2        : 3&lt;BR /&gt;
code            : 5&lt;BR /&gt;
string          : "Read Single Values"&lt;BR /&gt;
type            : "response"&lt;BR /&gt;
crc                     : 56253&lt;/P&gt;

&lt;P&gt;version     : "1.0.0"&lt;BR /&gt;
integrationType": "metric"&lt;BR /&gt;
action      : "created"&lt;BR /&gt;
tapid"      : 1&lt;BR /&gt;
port        : 2&lt;BR /&gt;
length      : 30&lt;BR /&gt;
timestamp   : 1580164556&lt;BR /&gt;
packet_id   : 626904&lt;BR /&gt;
protoco   l :"test"&lt;BR /&gt;
Address1    : 0&lt;BR /&gt;
FCode       : 1&lt;BR /&gt;
RValues     : 2&lt;BR /&gt;
reg1        : 3,4&lt;BR /&gt;
reg2        : 5,6&lt;BR /&gt;
reg3        : 7,8&lt;BR /&gt;
reg4        : 9,10&lt;BR /&gt;
reg5        : 11,12&lt;BR /&gt;
reg6        : 13,14&lt;BR /&gt;
reg7        : 15,16&lt;BR /&gt;
reg8        : 17,18&lt;BR /&gt;
reg9        : 19,20&lt;BR /&gt;
reg10       : 21,22&lt;BR /&gt;
reg11       : 23,24&lt;BR /&gt;
reg12       : 25,26&lt;BR /&gt;
reg13       : 27,28&lt;BR /&gt;
checksum    : 29,28&lt;BR /&gt;
Address2    : 3,&lt;BR /&gt;
code        : 3&lt;BR /&gt;
string      : "Read Multiple Values"&lt;BR /&gt;
type        : "response&lt;BR /&gt;
crc             : 18279&lt;/P&gt;

&lt;P&gt;If I do a simple data import of the samples I just gave and use JSON data type, I seem to get what I'm expecting except it looks like I get 2 fields that show AddressOut1 = 2 and then a AddressOut2 = 3, not a AddressOut1 = 2,3.&lt;BR /&gt;
Hope this makes sense.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2020 14:49:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471246#M146005</guid>
      <dc:creator>trtracy81</dc:creator>
      <dc:date>2020-02-13T14:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pairldelim kvdelim JSON problems</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471247#M146006</link>
      <description>&lt;P&gt;@trtracy81 Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | rename metrics.General.* as *, metrics.General.Indexes.*{} as *,metrics.TransportLayer.* as *,metrics.TransportLayer.FCode2.* as *,metrics.ApplicationLayer.Rail.Rail16 as Rail16
| eval AddressOut2 = mvindex(AddressOut1,1),AddressOut1 = mvindex(AddressOut1,0)
| foreach * [ | eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=mvjoin(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,",") ]
| table version,integrationType,action ,tapid,port ,length ,timestamp ,packet_id ,protocol,Address1,AddressOut1,AddressOut2,outputValue ,checksum ,Rail16,FCode ,RValues ,reg*,checksum ,Address2,code,string,type,crc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Sample Search&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data="{\"version\":\"1.0.0\",\"integrationType\":\"metric\",\"action\":\"created\",\"metrics\":{\"General\":{\"tapid\":1,\"port\":2,\"length\":16,\"timestamp\":1580164559,\"packet_id\":626910,\"protocol\":\"test\",\"Indexes\":{\"Address1\":[0],\"FCode\":[1],\"AddressOut1\":[2,3],\"outputValue\":[4,5],\"checksum\":[6,7]}},\"ApplicationLayer\":{\"Rail\":{\"Rail16\":1}},\"TransportLayer\":{\"Address2\":3,\"FCode2\":{\"code\":5,\"string\":\"Read Single Values\"},\"type\":\"response\",\"crc\":56253}}}|{\"version\":\"1.0.0\",\"integrationType\":\"metric\",\"action\":\"created\",\"metrics\":{\"General\":{\"tapid\":1,\"port\":2,\"length\":30,\"timestamp\":1580164556,\"packet_id\":626904,\"protocol\":\"test\",\"Indexes\":{\"Address1\":[0],\"FCode\":[1],\"RValues\":[2],\"reg1\":[3,4],\"reg2\":[5,6],\"reg3\":[7,8],\"reg4\":[9,10],\"reg5\":[11,12],\"reg6\":[13,14],\"reg7\":[15,16],\"reg8\":[17,18],\"reg9\":[19,20],\"reg10\":[21,22],\"reg11\":[23,24],\"reg12\":[25,26],\"reg13\":[27,28],\"checksum\":[29,28]}},\"ApplicationLayer\":{\"Registering\":{}},\"TransportLayer\":{\"Address2\":3,\"FCode2\":{\"code\":3,\"string\":\"Read Multiple Values\"},\"type\":\"response\",\"crc\":18279}}}
",data=split(data,"|") | mvexpand data | eval _raw=data 
| extract 
| rename metrics.General.* as *, metrics.General.Indexes.*{} as *,metrics.TransportLayer.* as *,metrics.TransportLayer.FCode2.* as *,metrics.ApplicationLayer.Rail.Rail16 as Rail16
| eval AddressOut2 = mvindex(AddressOut1,1),AddressOut1 = mvindex(AddressOut1,0)
| foreach * [ | eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=mvjoin(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,",") ]
| table version,integrationType,action ,tapid,port ,length ,timestamp ,packet_id ,protocol,Address1,AddressOut1,AddressOut2,outputValue ,checksum ,Rail16,FCode ,RValues ,reg*,checksum ,Address2,code,string,type,crc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Feb 2020 06:25:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471247#M146006</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-02-14T06:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract pairldelim kvdelim JSON problems</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471248#M146007</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"version\":\"1.0.0\",\"integrationType\":\"metric\",\"action\":\"created\",\"metrics\":{\"General\":{\"tapid\":1,\"port\":2,\"length\":16,\"timestamp\":1580164559,\"packet_id\":626910,\"protocol\":\"test\",\"Indexes\":{\"Address1\":[0],\"FCode\":[1],\"AddressOut1\":[2,3],\"outputValue\":[4,5],\"checksum\":[6,7]}},\"ApplicationLayer\":{\"Rail\":{\"Rail16\":1}},\"TransportLayer\":{\"Address2\":3,\"FCode2\":{\"code\":5,\"string\":\"Read Single Values\"},\"type\":\"response\",\"crc\":56253}}}|{\"version\":\"1.0.0\",\"integrationType\":\"metric\",\"action\":\"created\",\"metrics\":{\"General\":{\"tapid\":1,\"port\":2,\"length\":30,\"timestamp\":1580164556,\"packet_id\":626904,\"protocol\":\"test\",\"Indexes\":{\"Address1\":[0],\"FCode\":[1],\"RValues\":[2],\"reg1\":[3,4],\"reg2\":[5,6],\"reg3\":[7,8],\"reg4\":[9,10],\"reg5\":[11,12],\"reg6\":[13,14],\"reg7\":[15,16],\"reg8\":[17,18],\"reg9\":[19,20],\"reg10\":[21,22],\"reg11\":[23,24],\"reg12\":[25,26],\"reg13\":[27,28],\"checksum\":[29,28]}},\"ApplicationLayer\":{\"Registering\":{}},\"TransportLayer\":{\"Address2\":3,\"FCode2\":{\"code\":3,\"string\":\"Read Multiple Values\"},\"type\":\"response\",\"crc\":18279}}}"
| eval _raw=split(_raw,"|") 
| stats count by _raw 
| table _raw 
`comment("this is sample you provide")`
| spath 
| rename *{} as * 
| foreach * 
    [ eval lastname_&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=mvindex(split("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;","."),-1)] 
| foreach lastname_* 
    [ eval {&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;} = '&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;' 
    | fields - lastname_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;] 
| eval version=spath(_raw,"version"),integrationType=spath(_raw,"integrationType"),action=spath(_raw,"action") 
| table version,integrationType,action ,tapid,port ,length ,timestamp ,packet_id ,protocol,Address1,AddressOut1,outputValue ,checksum ,Rail16,FCode ,RValues ,reg*,checksum ,Address2,code,string,type,crc 
| foreach * 
    [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = mvjoin(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; ,",")]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 Feb 2020 05:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-pairldelim-kvdelim-JSON-problems/m-p/471248#M146007</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-02-15T05:34:10Z</dc:date>
    </item>
  </channel>
</rss>

