<?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 do I split an array in a .json file into multiple new events? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149596#M30461</link>
    <description>&lt;P&gt;Try something like this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your base search...&amp;gt; | table  timestamp, Date, Available | eval temp=mvzip(timestamp, mvzip(Date, Available,"###"), "###") | mvexpand temp | rex field=temp "(?&amp;lt;timestamp&amp;gt;.*)###(?&amp;lt;Date&amp;gt;.*)###(?&amp;lt;Available&amp;gt;.*)" | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have used the sample fields, you can try with your actual fields. Concept here is, you need to zip it with a delimiter (here ###) and expand it and extract it. This do the magic &lt;/P&gt;</description>
    <pubDate>Mon, 22 Aug 2016 18:55:01 GMT</pubDate>
    <dc:creator>vasanthmss</dc:creator>
    <dc:date>2016-08-22T18:55:01Z</dc:date>
    <item>
      <title>How do I split an array in a .json file into multiple new events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149593#M30458</link>
      <description>&lt;P&gt;Right now I have a json file that's formatted like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "Log Files":[
        {"Date":"2014-07-18 21:22:51", "Available Bytes(kb)":3960078, ...},
        {"Date":"2014-07-18 21:24:01", "Available Bytes(kb)":4001231, ...},
        {"Date":"2014-07-18 21:25:14", "Available Bytes(kb)":3872959, ...}]}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Right now it's showing up in Splunk as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;timestamp                Date                Available Bytes(kb)
2014-07-18 21:22:51:000  2014-07-18 21:22:51 3960078
                         2014-07-18 21:24:01 4001231
                         2014-07-18 21:25:14 3872959
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I split these up into individual events when I load the data? I can get the timestamp to correctly match the Date field, but it will still only give one date for the whole file, even though there are several lines that are each individual logs.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2014 22:29:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149593#M30458</guid>
      <dc:creator>dgutekunst</dc:creator>
      <dc:date>2014-07-18T22:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split an array in a .json file into multiple new events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149594#M30459</link>
      <description>&lt;P&gt;When you say "... when I load the data" do you mean at search time or index time?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 02:31:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149594#M30459</guid>
      <dc:creator>pwmcintyre</dc:creator>
      <dc:date>2016-08-22T02:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split an array in a .json file into multiple new events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149595#M30460</link>
      <description>&lt;P&gt;Is there anything in the envelope of this array that you want to keep or are you just interested in keeping the events inside the "Log Files" array?&lt;BR /&gt;
If the latter, setup props/transforms for your sourcetype to:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Get rid of the root '{' line &lt;/LI&gt;
&lt;LI&gt;Get rid of the array root line that contains "Log Files" &lt;/LI&gt;
&lt;LI&gt;Use SEDCMD to change "}," to "}" at the end of the lines&lt;/LI&gt;
&lt;LI&gt;Use SEDCMD to remove "]}"&lt;/LI&gt;
&lt;LI&gt;Set TIMESTAMP_PREFIX to &lt;CODE&gt;\{\"Date\":\"&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;That should result in individual, valid JSON events that should render fine in the UI. &lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 18:38:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149595#M30460</guid>
      <dc:creator>s2_splunk</dc:creator>
      <dc:date>2016-08-22T18:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I split an array in a .json file into multiple new events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149596#M30461</link>
      <description>&lt;P&gt;Try something like this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your base search...&amp;gt; | table  timestamp, Date, Available | eval temp=mvzip(timestamp, mvzip(Date, Available,"###"), "###") | mvexpand temp | rex field=temp "(?&amp;lt;timestamp&amp;gt;.*)###(?&amp;lt;Date&amp;gt;.*)###(?&amp;lt;Available&amp;gt;.*)" | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have used the sample fields, you can try with your actual fields. Concept here is, you need to zip it with a delimiter (here ###) and expand it and extract it. This do the magic &lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 18:55:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-split-an-array-in-a-json-file-into-multiple-new-events/m-p/149596#M30461</guid>
      <dc:creator>vasanthmss</dc:creator>
      <dc:date>2016-08-22T18:55:01Z</dc:date>
    </item>
  </channel>
</rss>

