<?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: How to split a json array into multiple events with separate timestamps? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/601108#M104743</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/1960"&gt;@Gilberto_Castil&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jun 2022 05:19:47 GMT</pubDate>
    <dc:creator>AnilPujar</dc:creator>
    <dc:date>2022-06-09T05:19:47Z</dc:date>
    <item>
      <title>How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139851#M28738</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Below is sample  json input I am getting from rest api:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ [-] 
    IPRequestLog: [ [-] 
     { [-] 
        access_key:  test 
        id:  0ac03844-a374-4237-9172-a7af9122bed2 
        ip_address:  192.168.1.245 
        requested_on:  2015-07-28 06:47:48 
        source_ip:  49.248.183.29 
     } 
     { [-] 
        access_key:  test 
        id:  7b1f5f38-77d1-453e-8a9e-e33f206474ff 
        ip_address:  192.168.1.240 
        requested_on:  2015-07-28 06:47:54 
        source_ip:  49.248.183.29 
     } 
     { [-] 
        access_key:  test 
        id:  83c6724b-2017-42fa-9cba-5c256d8d502e 
        ip_address:  192.168.1.249 
        requested_on:  2015-07-28 06:47:51 
        source_ip:  49.248.183.29 
     } 
   ] 
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Currently values within the arrays are clubbed into a single event and 1st timestamp value is recognised as event time. I tried adding the following in &lt;STRONG&gt;props.conf&lt;/STRONG&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[source::source_name]
TIME_PREFIX = requested_on":"
MAX_TIMESTAMP_LOOKAHEAD = 1000
BREAK_ONLY_BEFORE_DATE = false
MUST_BREAK_AFTER = },{
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does anybody know to split array into separate events with respective timestamps (in this case requested_on)?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 07:09:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139851#M28738</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2015-07-28T07:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139852#M28739</link>
      <description>&lt;P&gt;Just to clarify, did you want to do this at index time?&lt;BR /&gt;
I'm told you have splunk parse json quite easily, I haven't tried but it's worth researching?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 08:04:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139852#M28739</guid>
      <dc:creator>pwmcity</dc:creator>
      <dc:date>2015-07-28T08:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139853#M28740</link>
      <description>&lt;P&gt;Yes, I want to do this at index time.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 08:10:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139853#M28740</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2015-07-28T08:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139854#M28741</link>
      <description>&lt;P&gt;You would then need to SEDCMD in your props.conf to manipulate the data before the JSON transformation is done. See some readables here.&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/Data/Anonymizedatausingconfigurationfiles"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.4/Data/Anonymizedatausingconfigurationfiles&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://answers.splunk.com/answers/210096/how-to-configure-sedcmd-in-propsconf.html"&gt;http://answers.splunk.com/answers/210096/how-to-configure-sedcmd-in-propsconf.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 15:10:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139854#M28741</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-07-28T15:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139855#M28742</link>
      <description>&lt;P&gt;You can do this by manipulating the break liners and cleaning up the stuff that is not needed. For instance, assume your JSON string looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "IPRequestLog": [
        {
            "access_key": "test",
            "id": "0ac03844-a374-4237-9172-a7af9122bed2",
            "ip_address": "192.168.1.245",
            "requested_on": "2015-07-28 06:47:48",
            "source_ip": "49.248.183.29"
        },
        {
            "access_key": "test",
            "id": "0ac03844-a374-4237-9172-e33f206474ff",
            "ip_address": "192.168.1.245",
            "requested_on": "2015-07-28 06:47:54",
            "source_ip": "49.248.183.29"
        },
        {
            "access_key": "test",
            "id": "0ac03844-a374-4237-9172-5c256d8d502e",
            "ip_address": "192.168.1.245",
            "requested_on": "2015-07-28 06:47:51",
            "source_ip": "49.248.183.29"
        }
    ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can clean this up with this basic recipe:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# props.conf
[answers-1438103671]
BREAK_ONLY_BEFORE_DATE = false
BREAK_ONLY_BEFORE = (\{|\[\s+{)
MUST_BREAK_AFTER = (\}|\}\s+\])
SEDCMD-remove_header = s/(\{\s+.+?\[)//g
SEDCMD-remove_trailing_commas = s/\},/}/g
SEDCMD-remove_footer = s/\]\s+\}//g
TIME_PREFIX = \"requested_on\":\s+\"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Assume that your sourcetype is answers-1438103671. Your results should look like this:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/496i4408C61CF6E09297/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 17:37:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139855#M28742</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2015-07-28T17:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139856#M28743</link>
      <description>&lt;P&gt;If I had to parse something like this coming from an API, I would probably write a modular input.  That way you can use your language of choice to query the REST endpoint, pull the JSON, manipulate it into individual events, and send to splunk.  &lt;/P&gt;

&lt;P&gt;This is pretty advanced and requires some dev chops, but works very well.  Trying to do this via conf files is likely going to be brittle.  &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/AdvancedDev/ModInputsBasicExample"&gt;Relevant Documentation&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;EDIT:  Had a try at parsing this, and came up with a working example (that appears to be similar to the below answer, although I prefer using line_breakers when possible)  This only linebreaks on newline characters or commas not near a quote.  (So commas between events)  And it strips the outer portions of JSON where found.  &lt;/P&gt;

&lt;P&gt;NOTE: This assumes your JSON is actually coming in minified.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"IPRequestLog":[{"access_key":"test","id":"0ac03844-a374-4237-9172-a7af9122bed2","ip_address":"192.168.1.245","requested_on":"2015-07-28 06:47:48","source_ip":"49.248.183.29"},{"access_key":"test","id":"7b1f5f38-77d1-453e-8a9e-e33f206474ff","ip_address":"192.168.1.240","requested_on":"2015-07-28 06:47:54","source_ip":"49.248.183.29"},{"access_key":"test","id":"83c6724b-2017-42fa-9cba-5c256d8d502e","ip_address":"192.168.1.249","requested_on":"2015-07-28 06:47:51","source_ip":"49.248.183.29"}]}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[json_split]
SHOULD_LINEMERGE=false
LINE_BREAKER=((?&amp;lt;!"),|[\r\n]+)
SEDCMD-remove_prefix=s/{"IPRequestLog":\[//g
SEDCMD-remove_suffix=s/\]}//g
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/498i9EEBB1FFFAFD7957/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 17:41:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139856#M28743</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2015-07-28T17:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139857#M28744</link>
      <description>&lt;P&gt;@emiller42 &lt;BR /&gt;
This can be done on universal forwarder side ??&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2018 22:55:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139857#M28744</guid>
      <dc:creator>vj5</dc:creator>
      <dc:date>2018-06-26T22:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139858#M28745</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
 Thanks for the solution, it works as expected. Only thing extra we get as events is the starting and ending braces of the JSON.&lt;BR /&gt;
How do we overcome this?&lt;/P&gt;

&lt;P&gt;Thanks &lt;BR /&gt;
Shahid&lt;/P&gt;</description>
      <pubDate>Mon, 05 Nov 2018 19:04:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/139858#M28745</guid>
      <dc:creator>shahid285</dc:creator>
      <dc:date>2018-11-05T19:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/557097#M92186</link>
      <description>&lt;P&gt;I am in need of this exact solution, except it appears to stop after the first match in a json string?&amp;nbsp; How do i prevent that?&amp;nbsp; &amp;nbsp;for example if you look at the original post there are multiple "TEST" in that single json string.&amp;nbsp; I need to break these out into three records...&amp;nbsp; your response works but only on the first record.&amp;nbsp; any ideas?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2021 01:35:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/557097#M92186</guid>
      <dc:creator>pir8radio</dc:creator>
      <dc:date>2021-06-25T01:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/601107#M104742</link>
      <description>&lt;DIV&gt;Can somebody please help me with the props, the below data need to break into 3 events&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"retrRecResp":[&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"keyFields":[&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"key":"Domain",&lt;/DIV&gt;&lt;DIV&gt;"value": "login"&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"key":"Env",&lt;/DIV&gt;&lt;DIV&gt;"value": "Prod"&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;],&lt;/DIV&gt;&lt;DIV&gt;"payload" : {&lt;/DIV&gt;&lt;DIV&gt;"payloadDataObject":{},&lt;/DIV&gt;&lt;DIV&gt;"timestamp":"Wed Jan 20 21:42:28 UTC 2021"&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;"consumerId":"Splunk",&lt;/DIV&gt;&lt;DIV&gt;"entityState": "Default"&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"keyFields":[&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"key":"Domain",&lt;/DIV&gt;&lt;DIV&gt;"value": "login"&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"key":"Env",&lt;/DIV&gt;&lt;DIV&gt;"value": "SIT"&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;],&lt;/DIV&gt;&lt;DIV&gt;"payload" : {&lt;/DIV&gt;&lt;DIV&gt;"payloadDataObject":{},&lt;/DIV&gt;&lt;DIV&gt;"timestamp":"Wed Jan 20 21:42:28 UTC 2021"&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;"consumerId":"Splunk",&lt;/DIV&gt;&lt;DIV&gt;"entityState": "Default"&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"keyFields":[&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"key":"Domain",&lt;/DIV&gt;&lt;DIV&gt;"value": "login"&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;"key":"Env",&lt;/DIV&gt;&lt;DIV&gt;"value": "uat"&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;],&lt;/DIV&gt;&lt;DIV&gt;"payload" : {&lt;/DIV&gt;&lt;DIV&gt;"payloadDataObject":{},&lt;/DIV&gt;&lt;DIV&gt;"timestamp":"Wed Feb 20 21:42:28 UTC 2021"&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;"consumerId":"Splunk",&lt;/DIV&gt;&lt;DIV&gt;"entityState": "Default"&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;]&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Jun 2022 05:17:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/601107#M104742</guid>
      <dc:creator>AnilPujar</dc:creator>
      <dc:date>2022-06-09T05:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/601108#M104743</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/1960"&gt;@Gilberto_Castil&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 05:19:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/601108#M104743</guid>
      <dc:creator>AnilPujar</dc:creator>
      <dc:date>2022-06-09T05:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a json array into multiple events with separate timestamps?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/601110#M104744</link>
      <description>&lt;P&gt;I don't know if you're aware of it but you've just dug up a thread that's almost 7 years old.&lt;/P&gt;&lt;P&gt;Also, your problem is indeed similar, but different.&lt;/P&gt;&lt;P&gt;So you'll get a best chance of receiving help if you start a new thread (you can post a link to this threaf for reference if you did try something based on the solution presented here).&lt;/P&gt;&lt;P&gt;And paste your event sample in a preformated or code block so it stays properly indented - it's much more readable that way.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 05:48:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-split-a-json-array-into-multiple-events-with-separate/m-p/601110#M104744</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-06-09T05:48:38Z</dc:date>
    </item>
  </channel>
</rss>

