<?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: get the last element of repeating json payload in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506430#M141693</link>
    <description>&lt;P&gt;Hello Kamlesh, thanks for your reply&lt;BR /&gt;I am interested in getting the last payload.&lt;BR /&gt;dedup would eliminate duplicates, but it does not ensure that it gets me the last payload.&lt;BR /&gt;Is there any way, that would get me the last payload from&amp;nbsp; repeating payloads pattern?&lt;/P&gt;</description>
    <pubDate>Sun, 28 Jun 2020 22:47:34 GMT</pubDate>
    <dc:creator>sharathk0525</dc:creator>
    <dc:date>2020-06-28T22:47:34Z</dc:date>
    <item>
      <title>get the last element of repeating json payload</title>
      <link>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506091#M141597</link>
      <description>&lt;P&gt;I have a repeating j son payload appearing in my logs.&lt;BR /&gt;I am interested in capturing the last payload from the logs.&lt;BR /&gt;right now I am seeing 3 events with below search query, but I wanted the last event&lt;BR /&gt;here is my search query&lt;/P&gt;&lt;P&gt;search query&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc_applications cf_space_name=production cf_app_name="my-app-name" "\"newAction\":\"request-change"\" AND "Final obj-1----------" 
| rex field=_raw "Final obj-1----------(?P&amp;lt;json_data_1&amp;gt;\{.*\})"

| eval json_data = mvindex(json_data_1, -1)
| spath input=json_data
| rename data.cRID as CRID
| eval Attachment_Count = spath(json_data, "changeAttachment{}")
| eval Approver_Count = spath(json_data, "changeApprover{}")
| eval Config_Count = spath(json_data, "changeConfigItem{}")| stats count(Attachment_Count) as Attachment_Count, count(Approver_Count) as Approver_Count, count(Config_Count) as Config_Item_Count by CRID&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;this is how my logs appear&lt;BR /&gt;you will not see this text(====start====) (====end===) in the logs, just for understanding purpose I added this line, to differentiate repeating logs&lt;BR /&gt;&lt;BR /&gt;The logs are exactly identical and repeating in pattern&lt;/P&gt;&lt;P&gt;payload is here&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;this is how my logs appear
you will not see this text(====start====) (====end===) in the logs, just for understanding purpose I added this line, to differentiate repeating logs

The logs are exactly identical and repeating in pattern

================start=============

Final obj-1----------
{
"action":"Waiting Approval",
"changeConfigItem":[
{}

],

"changeApprover":[
{}

],

"changeAttachment":[
{},
{}

]
"newAction":"request-change"
}

================end=============

==========start==================

Final obj-1----------
{
"action":"Waiting Approval",
"changeConfigItem":[
{}

],

"changeApprover":[
{}

],

"changeAttachment":[
{},
{}

],
 "data":{ "cRID":"1111"}


"newAction":"request-change"
}
==========end==================

==========start==================

Final obj-1----------
{
"action":"Waiting Approval",
"changeConfigItem":[
{}

],

"changeApprover":[
{}

],

"changeAttachment":[
{},
{}

]
"newAction":"request-change"
},
 "data":{ "cRID":"1111"}
==========end==================&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 04:43:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506091#M141597</guid>
      <dc:creator>sharathk0525</dc:creator>
      <dc:date>2020-06-25T04:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: get the last element of repeating json payload</title>
      <link>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506097#M141600</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/222962"&gt;@sharathk0525&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please provide valid sample JSON from your _raw and your expected output from that sample. That will make us clear understanding about your requirement. Please make sure _raw events should be the single liner JSON event.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;Kamlesh Vaghela&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 06:33:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506097#M141600</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-06-25T06:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: get the last element of repeating json payload</title>
      <link>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506150#M141618</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is how my logs appear&lt;BR /&gt;you will not see this text(====start====) (====end===) in the logs, just for understanding purpose I added this line, to differentiate repeating logs&lt;/P&gt;&lt;P&gt;The logs are exactly identical and repeating in pattern&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;================start=============

Final obj-1----------
{
"action":"Waiting Approval",
"changeConfigItem":[
{"ciItem" : "1"}

],

"changeApprover":[
{"name" : "test"	}

],

"changeAttachment":[
{
"fileName" : "abc.txt"},
{"fileName" : "abc.txt"}

]
"newAction":"request-change"
}

================end=============

==========start==================

Final obj-1----------
{
"action":"Waiting Approval",
"changeConfigItem":[
{"ciItem" : "1"}

],

"changeApprover":[
{"name" : "test"	}

],

"changeAttachment":[
{
"fileName" : "abc.txt"},
{"fileName" : "abc.txt"}

]
"newAction":"request-change"
}
==========end==================

==========start==================

Final obj-1----------
{
"action":"Waiting Approval",
"changeConfigItem":[
{"ciItem" : "1"}

],

"changeApprover":[
{"name" : "test"	}

],

"changeAttachment":[
{
"fileName" : "abc.txt"},
{"fileName" : "abc.txt"}

]
"newAction":"request-change"
}
==========end==================&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;searchQuery&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;here is my search query

search query
index=abc_applications cf_space_name=production cf_app_name="my-app-name" "\"newAction\":\"request-change"\" AND "Final obj-1----------" 
| rex field=_raw "Final obj-1----------(?P&amp;lt;json_data_1&amp;gt;\{.*\})"

| eval json_data = mvindex(json_data_1, -1)
| spath input=json_data
| rename data.cRID as CRID
| eval Attachment_Count = spath(json_data, "changeAttachment{}")
| eval Approver_Count = spath(json_data, "changeApprover{}")
| eval Config_Count = spath(json_data, "changeConfigItem{}")| stats count(Attachment_Count) as Attachment_Count, count(Approver_Count) as Approver_Count, count(Config_Count) as Config_Item_Count by CRID&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;current output&lt;BR /&gt;I am getting output as, its giving cumulative results&lt;/P&gt;&lt;TABLE border="1" width="63.87878787878788%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="16.666666666666668%"&gt;CRID&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;Attachment_Count&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;Approver_Count&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;Config_Item_Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="16.666666666666668%"&gt;1111&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;6&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;3&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expected/desired output&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="16.666666666666668%"&gt;CRID&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;Attachment_Count&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;Approver_Count&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;Config_Item_Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="16.666666666666668%"&gt;1111&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;2&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;1&lt;/TD&gt;&lt;TD width="16.666666666666668%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hope this helps your understanding&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 13:33:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506150#M141618</guid>
      <dc:creator>sharathk0525</dc:creator>
      <dc:date>2020-06-25T13:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: get the last element of repeating json payload</title>
      <link>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506182#M141628</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/222962"&gt;@sharathk0525&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope data.cRID field will come in your event.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc_applications cf_space_name=production cf_app_name="my-app-name" "\"newAction\":\"request-change"\" AND "Final obj-1----------" 
| rex field=_raw "Final obj-1----------(?P&amp;lt;json_data_1&amp;gt;\{.*\})"

| eval json_data = mvindex(json_data_1, -1)
| spath input=json_data
| dedup data.cRID
| rename data.cRID as CRID
| eval Attachment_Count = spath(json_data, "changeAttachment{}")
| eval Approver_Count = spath(json_data, "changeApprover{}")
| eval Config_Count = spath(json_data, "changeConfigItem{}")| stats count(Attachment_Count) as Attachment_Count, count(Approver_Count) as Approver_Count, count(Config_Count) as Config_Item_Count by CRID&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Can you please try this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 15:50:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506182#M141628</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-06-25T15:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: get the last element of repeating json payload</title>
      <link>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506430#M141693</link>
      <description>&lt;P&gt;Hello Kamlesh, thanks for your reply&lt;BR /&gt;I am interested in getting the last payload.&lt;BR /&gt;dedup would eliminate duplicates, but it does not ensure that it gets me the last payload.&lt;BR /&gt;Is there any way, that would get me the last payload from&amp;nbsp; repeating payloads pattern?&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jun 2020 22:47:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506430#M141693</guid>
      <dc:creator>sharathk0525</dc:creator>
      <dc:date>2020-06-28T22:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: get the last element of repeating json payload</title>
      <link>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506467#M141704</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/222962"&gt;@sharathk0525&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes dedup will&amp;nbsp;removes the events that contain an identical combination of values for the fields that you specify.&amp;nbsp;dedup will gives you most recent event on the basis of data.cRID. if you looking for most recent event then dedup is best for you. In this case you can easily ignore stats also.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.0.4/SearchReference/Dedup" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/8.0.4/SearchReference/Dedup&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please try this for validate data?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc_applications cf_space_name=production cf_app_name="my-app-name" "\"newAction\":\"request-change"\" AND "Final obj-1----------" 
| rex field=_raw "Final obj-1----------(?P&amp;lt;json_data_1&amp;gt;\{.*\})"

| eval json_data = mvindex(json_data_1, -1)
| spath input=json_data
| dedup data.cRID
| rename data.cRID as CRID
| eval Attachment_Count = spath(json_data, "changeAttachment{}")
| eval Approver_Count = spath(json_data, "changeApprover{}")
| eval Config_Count = spath(json_data, "changeConfigItem{}")
| table _time CRID  Attachment_Count, Approver_Count,  Config_Item_Count &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 05:03:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/get-the-last-element-of-repeating-json-payload/m-p/506467#M141704</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-06-29T05:03:42Z</dc:date>
    </item>
  </channel>
</rss>

