<?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 separate json payload to separate events in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452023#M78342</link>
    <description>&lt;P&gt;my search :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SEARCH...
| rex field=Message "^(?&amp;lt;Short&amp;gt;.*),\sRequestBody:\s(?&amp;lt;ShortMessage&amp;gt;[^\s]+)\".*$" 
| spath input=ShortMessage
| rename sapResponseData{}.contractAccounts{}.nameId AS NameId sapResponseData{}.contractAccounts{}.contractAccount AS ContractAccountNumber sapResponseData{}.contractAccounts{}.sapResponses{}.contractNumber AS ContractNumber sapResponseData{}.contractAccounts{}.sapResponses{}.messageId AS messageId sapResponseData{}.contractAccounts{}.sapResponses{}.messageNumber AS messageNumber sapResponseData{}.contractAccounts{}.sapResponses{}.dataset AS dataSet metadata.correlationId AS CorrelationId metadata.sendDate AS SendDate metadata.sendTime AS SendTime 
| lookup dataset_lookup.csv dataset AS dataSet OUTPUTNEW usage AS Usage
| table _time NameId ContractAccountNumber ContractNumber messageId messageNumber dataSet Usage CorrelationId SendDate SendTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;new field after split field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
  "sapResponseData": [
    {
      "responseOriginatedIn": "ERROR",
      "contractAccounts": [
        {
          "nameId": "ABC_999999999999999",
          "contractAccount": "888888888888",
          "sapResponses": [
            {
              "contractNumber": 999999999,
              "responseCode": "002",
              "messageId": "DEF456",
              "messageNumber": "031",
              "dataset": "002"
            },
            {
              "contractNumber": 999999999,
              "responseCode": "002",
              "messageId": "ABC123",
              "messageNumber": "094",
              "dataset": "001"
            }
          ]
        }
      ]
    }
  ],
  "metadata": {
    "correlationId": "Correlation_ID",
    "priority": "LOW",
    "sendDate": "2019-03-21",
    "sendTime": 224813
  }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;currently sapResponses all appear in the same field in the table&lt;/P&gt;

&lt;P&gt;How to create new events per sapResponse ? and keep metadata for all events ?&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2019 13:20:50 GMT</pubDate>
    <dc:creator>Esky73</dc:creator>
    <dc:date>2019-03-21T13:20:50Z</dc:date>
    <item>
      <title>separate json payload to separate events</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452023#M78342</link>
      <description>&lt;P&gt;my search :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SEARCH...
| rex field=Message "^(?&amp;lt;Short&amp;gt;.*),\sRequestBody:\s(?&amp;lt;ShortMessage&amp;gt;[^\s]+)\".*$" 
| spath input=ShortMessage
| rename sapResponseData{}.contractAccounts{}.nameId AS NameId sapResponseData{}.contractAccounts{}.contractAccount AS ContractAccountNumber sapResponseData{}.contractAccounts{}.sapResponses{}.contractNumber AS ContractNumber sapResponseData{}.contractAccounts{}.sapResponses{}.messageId AS messageId sapResponseData{}.contractAccounts{}.sapResponses{}.messageNumber AS messageNumber sapResponseData{}.contractAccounts{}.sapResponses{}.dataset AS dataSet metadata.correlationId AS CorrelationId metadata.sendDate AS SendDate metadata.sendTime AS SendTime 
| lookup dataset_lookup.csv dataset AS dataSet OUTPUTNEW usage AS Usage
| table _time NameId ContractAccountNumber ContractNumber messageId messageNumber dataSet Usage CorrelationId SendDate SendTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;new field after split field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
  "sapResponseData": [
    {
      "responseOriginatedIn": "ERROR",
      "contractAccounts": [
        {
          "nameId": "ABC_999999999999999",
          "contractAccount": "888888888888",
          "sapResponses": [
            {
              "contractNumber": 999999999,
              "responseCode": "002",
              "messageId": "DEF456",
              "messageNumber": "031",
              "dataset": "002"
            },
            {
              "contractNumber": 999999999,
              "responseCode": "002",
              "messageId": "ABC123",
              "messageNumber": "094",
              "dataset": "001"
            }
          ]
        }
      ]
    }
  ],
  "metadata": {
    "correlationId": "Correlation_ID",
    "priority": "LOW",
    "sendDate": "2019-03-21",
    "sendTime": 224813
  }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;currently sapResponses all appear in the same field in the table&lt;/P&gt;

&lt;P&gt;How to create new events per sapResponse ? and keep metadata for all events ?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 13:20:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452023#M78342</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2019-03-21T13:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: separate json payload to separate events</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452024#M78343</link>
      <description>&lt;P&gt;You can look into &lt;CODE&gt;mvexpand&lt;/CODE&gt; with your JSON array to explode each event into multiples. As an alternative, Cribl allows you to pre-process events in the ingestion pipeline and we include a function called JSON Unroll which allows you to create an event per entry an a JSON array. &lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 15:03:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452024#M78343</guid>
      <dc:creator>coccyx</dc:creator>
      <dc:date>2019-03-21T15:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: separate json payload to separate events</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452025#M78344</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; SEARCH...
 | rex field=Message "^(?&amp;lt;Short&amp;gt;.*),\sRequestBody:\s(?&amp;lt;ShortMessage&amp;gt;[^\s]+)\".*$" 
 | spath input=ShortMessage
 | rename sapResponseData{}.contractAccounts{}.* AS *  sapResponseData{}.contractAccounts{}.sapResponses{}.*  metadata.* AS *
 | lookup dataset_lookup.csv dataset OUTPUTNEW usage AS Usage
 | table _time nameId contractAccount contractNumber messageId messageNumber dataset Usage correlationId sendDate sendTime
| eval temp=mvzip(contractNumber,mvzip(messageId,mvzip(messageNumber,dataset,"|"),"|"),"|") 
| mvexpand temp | rex field=temp "(?&amp;lt;contractNumber&amp;gt;]^\|]+)\|(?&amp;lt;messageId&amp;gt;]^\|]+)\|(?&amp;lt;messageNumber&amp;gt;]^\|]+)\|(?&amp;lt;dataset&amp;gt;]^\|]+)" | fields - temp 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Mar 2019 19:29:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452025#M78344</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-03-21T19:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: separate json payload to separate events</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452026#M78345</link>
      <description>&lt;P&gt;Hi - thanks - i tried mvexpand initially but that gave me a duplicate event.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2019 11:49:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452026#M78345</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2019-03-24T11:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: separate json payload to separate events</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452027#M78346</link>
      <description>&lt;P&gt;Hi Thanks for answering - this has no effect :&lt;/P&gt;

&lt;P&gt;i still have the following for contractNumber,messageId,messageNumber,dataset&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;contractNumber  messageId   messageNumber   dataset
123456          12345       0123            001
123456          67891       4567            002
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Mar 2019 12:05:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452027#M78346</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2019-03-24T12:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: separate json payload to separate events</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452028#M78347</link>
      <description>&lt;P&gt;I think i figured it out with help from here :&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/25653/mvexpand-multiple-multi-value-fields.html"&gt;https://answers.splunk.com/answers/25653/mvexpand-multiple-multi-value-fields.html&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=Message "^(?&amp;lt;Short&amp;gt;.*),\sRequestBody:\s(?&amp;lt;ShortMessage&amp;gt;[^\s]+)\".*$" 
| spath input=ShortMessage 
| rename sapResponseData{}.contractAccounts{}.* AS * metadata.* AS * sapResponseData{}.contractAccounts{}.sapResponses{}.* AS * 
| eval reading=mvzip(contractNumber, messageId) 
| eval reading=mvzip(reading, dataset) 
| eval reading=mvzip(reading, messageNumber) 
| mvexpand reading 
| makemv reading delim="," 
| eval contractNumber=mvindex(reading, 0) 
| eval messageId=mvindex(reading, 1) 
| eval messageNumber=mvindex(reading, -1) 
| eval dataset=mvindex(reading, 2) 
| lookup dataset_lookup.csv dataset OUTPUTNEW usage AS Usage 
| table _time nameId contractAccount contractNumber messageId messageNumber dataset Usage correlationId sendDate sendTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Mar 2019 12:24:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452028#M78347</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2019-03-24T12:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: separate json payload to separate events</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452029#M78348</link>
      <description>&lt;P&gt;Click &lt;CODE&gt;Accept&lt;/CODE&gt; on your answer to close the question.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2019 13:08:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/separate-json-payload-to-separate-events/m-p/452029#M78348</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-03-24T13:08:32Z</dc:date>
    </item>
  </channel>
</rss>

