<?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: Parse Nested JSON Array into Splunk Table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422158#M121235</link>
    <description>&lt;P&gt;I get about half of this just reading it.  I need to run it and rip it apart.&lt;/P&gt;</description>
    <pubDate>Sun, 01 Mar 2020 07:53:35 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2020-03-01T07:53:35Z</dc:date>
    <item>
      <title>Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422153#M121230</link>
      <description>&lt;P&gt;I have the below JSON event with nested array in splunk -:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
"items":
    [
        {
            "parts":
                [
                    {
                        "code":"1","var":"","pNum":"101","counter":1019
                    },
                    {
                        "code":"0","var":"","pNum":"102","counter":1029
                    }
                ],
            "se":"A1",
            "so":"111"
        },
        {
            "parts":
                [
                    {
                        "code":"1","var":"","pNum":"301","counter":3019
                    },
                    {
                        "code":"0","var":"","pNum":"302","counter":3029
                    }
                ],
            "se":"A3",
            "so":"333"
        },
        {
            "parts":
                [
                    {
                        "code":"0","var":"","pNum":"401","counter":4019
                    }
                ],
            "se":"A4",
            "so":"444"
        },
        {
            "parts":
                [
                    {
                        "code":"1","var":"","pNum":"501","counter":5019
                    }
                ],
            "se":"A5",
            "so":"555"
        }
    ],
"id":"x.9110790",
"cr":"x-273169"
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to extract this JSON into the below Splunk table -:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="expected_output_table"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/7431i0B4D252E581BA53D/image-size/large?v=v2&amp;amp;px=999" role="button" title="expected_output_table" alt="expected_output_table" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I tried to use spath as below but it is only giving wrong results given below -:&lt;/P&gt;

&lt;P&gt;|makeresults | eval _raw="{ \"items\": [ { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"101\",\"counter\":1019 }, { \"code\":\"0\",\"var\":\"\",\"pNum\":\"102\",\"counter\":1029 } ], \"se\":\"A1\", \"so\":\"111\" }, { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"301\",\"counter\":3019 }, { \"code\":\"0\",\"var\":\"\",\"pNum\":\"302\",\"counter\":3029 } ], \"se\":\"A3\", \"so\":\"333\" }, { \"parts\": [ { \"code\":\"0\",\"var\":\"\",\"pNum\":\"401\",\"counter\":4019 } ], \"se\":\"A4\", \"so\":\"444\" }, { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"501\",\"counter\":5019 } ], \"se\":\"A5\", \"so\":\"555\" } ], \"id\":\"x.9110790\", \"cr\":\"x-273169\" }" |spath |rename items as * | table id, cr,items{}.*&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="splunk_actual_output"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/7432i4719E16F98DDA23A/image-size/large?v=v2&amp;amp;px=999" role="button" title="splunk_actual_output" alt="splunk_actual_output" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I am trying to parse the JSON type splunk logs for the first time. So please help with any hints to solve this.&lt;BR /&gt;
 Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2019 02:32:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422153#M121230</guid>
      <dc:creator>kripzadamas</dc:creator>
      <dc:date>2019-08-02T02:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422154#M121231</link>
      <description>&lt;P&gt;Hello @kripzadamas,&lt;/P&gt;

&lt;P&gt;check the following, it meets your requirements. I got the idea from the documentation (botton of this page &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath&lt;/A&gt;).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval _raw="{ \"items\": [ { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"101\",\"counter\":1019 }, { \"code\":\"0\",\"var\":\"\",\"pNum\":\"102\",\"counter\":1029 } ], \"se\":\"A1\", \"so\":\"111\" }, { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"301\",\"counter\":3019 }, { \"code\":\"0\",\"var\":\"\",\"pNum\":\"302\",\"counter\":3029 } ], \"se\":\"A3\", \"so\":\"333\" }, { \"parts\": [ { \"code\":\"0\",\"var\":\"\",\"pNum\":\"401\",\"counter\":4019 } ], \"se\":\"A4\", \"so\":\"444\" }, { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"501\",\"counter\":5019 } ], \"se\":\"A5\", \"so\":\"555\" } ], \"id\":\"x.9110790\", \"cr\":\"x-273169\" }" 
| spath
| table _raw,cr,id
| spath path=items{}
| rename items{} as items
| mvexpand items
| spath input=items
| rename parts{}.code as code parts{}.counter as counter parts{}.pNum as pNum parts{}.var as var  
| eval x=mvzip(code,mvzip(counter,pNum))
| table cr,id,x,var,se,so
| mvexpand x
| eval x = split(x,",") | eval code=mvindex(x,0)| eval counter=mvindex(x,1)| eval pNum=mvindex(x,2)
| table id,cr,se,so,code,var,pNum,counter
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Aug 2019 08:03:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422154#M121231</guid>
      <dc:creator>poete</dc:creator>
      <dc:date>2019-08-08T08:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422155#M121232</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{ \"items\": [ { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"101\",\"counter\":1019 }, { \"code\":\"0\",\"var\":\"\",\"pNum\":\"102\",\"counter\":1029 } ], \"se\":\"A1\", \"so\":\"111\" }, { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"301\",\"counter\":3019 }, { \"code\":\"0\",\"var\":\"\",\"pNum\":\"302\",\"counter\":3029 } ], \"se\":\"A3\", \"so\":\"333\" }, { \"parts\": [ { \"code\":\"0\",\"var\":\"\",\"pNum\":\"401\",\"counter\":4019 } ], \"se\":\"A4\", \"so\":\"444\" }, { \"parts\": [ { \"code\":\"1\",\"var\":\"\",\"pNum\":\"501\",\"counter\":5019 } ], \"se\":\"A5\", \"so\":\"555\" } ], \"id\":\"x.9110790\", \"cr\":\"x-273169\" }" 
| rex mode=sed "s/}, {/}# {/g" 
| eval raw=split(_raw,"#") 
| mvexpand raw 
| fields - _* 
| streamstats count(eval(match(raw,"\["))) as session 
| rex field=raw max_match=0 "(?&amp;lt;fieldnamevalue&amp;gt;\"\S+?\:[^ ,]+)" 
| fields fieldnamevalue 
| streamstats current=f count as session 
| mvexpand fieldnamevalue 
| rex field=fieldnamevalue "(?&amp;lt;fieldname&amp;gt;.*):(?&amp;lt;fieldvalue&amp;gt;.*)"
| foreach field* [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = trim('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' ,"\"")]
| xyseries session fieldname fieldvalue
| reverse
| filldown
| reverse
| eval cr="x-".(tonumber(mvindex(split(cr,"-"),1)) + session) ,id="x.".(tonumber(mvindex(split(id,"."),1)) + session)
| table id,cr,se,so,code,var,pNum,counter
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 01 Mar 2020 05:37:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422155#M121232</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-01T05:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422156#M121233</link>
      <description>&lt;P&gt;This is nasty but...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{
 \"items\":
     [
         {
             \"parts\":
                 [
                     {
                         \"code\":\"1\",\"var\":\"\",\"pNum\":\"101\",\"counter\":1019
                     },
                     {
                         \"code\":\"0\",\"var\":\"\",\"pNum\":\"102\",\"counter\":1029
                     }
                 ],
             \"se\":\"A1\",
             \"so\":\"111\"
             },
         {
             \"parts\":
                 [
                     {
                         \"code\":\"1\",\"var\":\"\",\"pNum\":\"301\",\"counter\":3019
                     },
                     {
                         \"code\":\"0\",\"var\":\"\",\"pNum\":\"302\",\"counter\":3029
                     }
                 ],
             \"se\":\"A3\",
             \"so\":\"333\"
             },
         {
             \"parts\":
                 [
                     {
                         \"code\":\"0\",\"var\":\"\",\"pNum\":\"401\",\"counter\":4019
                     }
                 ],
             \"se\":\"A4\",
             \"so\":\"444\"
             },
         {
             \"parts\":
                 [
                     {
                         \"code\":\"1\",\"var\":\"\",\"pNum\":\"501\",\"counter\":5019
                     }
                 ],
             \"se\":\"A5\",
             \"so\":\"555\"
             }
     ],
 \"id\":\"x.9110790\",
 \"cr\":\"x-273169\"
     }" 

| rename COMMENT AS "Everything above generates sample events; everything below is your solution"

| rex "(?ms)\"id\":\"(?&amp;lt;id&amp;gt;[^\"]+).*?\"cr\":\"(?&amp;lt;cr&amp;gt;[^\"]+)" 
| rex max_match=0 "(?ms)[\r\n\s]+\"parts\":[\r\n\s]+(?&amp;lt;parts&amp;gt;.*?\")[\r\n\s]+}" 
| fields - _raw
| mvexpand parts
| rex field=parts "(?ms)\"se\":\"(?&amp;lt;se&amp;gt;[^\"]+).*?\"so\":\"(?&amp;lt;so&amp;gt;[^\"]+)"
| rex field=parts max_match=0 "(?ms)[\r\n\s]+{[\r\n\s]+(?&amp;lt;part&amp;gt;[^\r\n]+)"
| fields - parts
| mvexpand part
| rex field=part max_match=0 "\"(?&amp;lt;key&amp;gt;[^\"]+)\":\"?(?&amp;lt;val&amp;gt;[^\",]+)"
| eval _raw = mvzip(key, val, "=")
| fields - part key val
| kv
| table id cr se so code var pNum counter
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 01 Mar 2020 07:02:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422156#M121233</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-01T07:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422157#M121234</link>
      <description>&lt;P&gt;&lt;CODE&gt;"(?ms)[\r\n\s]+{[\r\n\s]+(?&amp;lt;part&amp;gt;[^\r\n]+)"&lt;/CODE&gt;&lt;BR /&gt;
I couldn't write this regex.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2020 07:39:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422157#M121234</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-01T07:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422158#M121235</link>
      <description>&lt;P&gt;I get about half of this just reading it.  I need to run it and rip it apart.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2020 07:53:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422158#M121235</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-01T07:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422159#M121236</link>
      <description>&lt;P&gt;We need a &lt;CODE&gt;fillup&lt;/CODE&gt; command.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2020 07:54:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422159#M121236</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-01T07:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422160#M121237</link>
      <description>&lt;P&gt;I am not too sure that I should have...&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2020 07:55:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422160#M121237</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-01T07:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422161#M121238</link>
      <description>&lt;P&gt;OR &lt;CODE&gt;filldown desc&lt;/CODE&gt; is fine also, too .&lt;/P&gt;</description>
      <pubDate>Sun, 01 Mar 2020 08:03:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422161#M121238</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-01T08:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Nested JSON Array into Splunk Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422162#M121239</link>
      <description>&lt;P&gt;Yours should have ended like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=fieldnamevalue "\"?(?&amp;lt;fieldname&amp;gt;[^:\"]+)\"?:\"?(?&amp;lt;fieldvalue&amp;gt;[^:\"]+)\"?" 
| eval {fieldname} = fieldvalue 
| fields - fieldnamevalue fieldname fieldvalue 
| stats values(*) AS * BY session 
| reverse 
| filldown 
| table id,cr,se,so,code,var,pNum,counter 
| reverse
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Mar 2020 08:37:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Parse-Nested-JSON-Array-into-Splunk-Table/m-p/422162#M121239</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-03-03T08:37:42Z</dc:date>
    </item>
  </channel>
</rss>

