<?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: Extract Json and non-json data from single event in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390136#M99259</link>
    <description>&lt;P&gt;@nareshinsvu &lt;/P&gt;

&lt;P&gt;1) If you drop unwanted text you will be indexing less amount of data. Hence save license accordingly. However, seems like you need to extract &lt;CODE&gt;Testing&lt;/CODE&gt; from regex pattern as well. So, may not be applicable for you.&lt;BR /&gt;
2) Please try the following regex which extracts &lt;CODE&gt;myField&lt;/CODE&gt; with &lt;CODE&gt;Testing&lt;/CODE&gt;. Since regular expression will be strictly based on the pattern in your data, you would need to tweak this and test on regex101.com. I have saved the sample data at the following location: &lt;A href="https://regex101.com/r/GCzdbZ/1"&gt;https://regex101.com/r/GCzdbZ/1&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "\] DEBUG ([^\s]+)\s+-\s+(?&amp;lt;myField&amp;gt;[^\s]+)\sCommand response is(?ms)(?&amp;lt;_raw&amp;gt;.*)" 
| spath
|  table myField *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Do accept/up-vote the answer if your issue is resolved!&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2019 15:46:08 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2019-07-17T15:46:08Z</dc:date>
    <item>
      <title>Extract Json and non-json data from single event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390133#M99256</link>
      <description>&lt;P&gt;Hello Champions,&lt;/P&gt;

&lt;P&gt;Need your help in extracting mixed data. Below is my sample data. I indexed it as a single event with SHOULD_LINEMERGE =TRUE. Now I want to extract "username" value only from "appliactionCredential" but not from "Response". Is there an easy way to extract JSON fileds without saving it as _json sourcetype? Because, I wanted to extract the timestamp and command as well from the 1st line.&lt;/P&gt;

&lt;P&gt;2019-06-11_00:06:53.356 [https-openssl-apr-443-exec-70] DEBUG c.audit.AuditingAspect - Testing Command response is&lt;BR /&gt;
{&lt;BR /&gt;
  "Response" : {&lt;BR /&gt;
    "status" : "ACCEPTED",&lt;BR /&gt;
    "credential" : {&lt;BR /&gt;
      "username" : "TestOnline",&lt;BR /&gt;
      "failedLoginAttempts" : 0,&lt;BR /&gt;
      "failedPwdResetAttempts" : 0,&lt;BR /&gt;
      "passwordSecurity" : 1,&lt;BR /&gt;
      "type" : "APPLICATION"&lt;BR /&gt;
    },&lt;BR /&gt;
    "appliactionCredential" : {&lt;BR /&gt;
      "username" : "Testlogin",&lt;BR /&gt;
      "failedLoginAttempts" : 0,&lt;BR /&gt;
      "failedPwdResetAttempts" : 0,&lt;BR /&gt;
      "passwordSecurity" : 1,&lt;BR /&gt;
      "type" : "APPLICATION"&lt;BR /&gt;
    },&lt;BR /&gt;
    "successful" : true,&lt;BR /&gt;
    "userId" : 00001&lt;BR /&gt;
  },&lt;BR /&gt;
  "code" : "00",&lt;BR /&gt;
  "description" : "ACCEPTED",&lt;BR /&gt;
  "auditId" : "audit123",&lt;BR /&gt;
  "messageId" : "message123",&lt;BR /&gt;
  "txnTime" : 1560175613200,&lt;BR /&gt;
  },&lt;BR /&gt;
    "Profile" : {&lt;BR /&gt;
      "systemItemStatus" : "ENABLED",&lt;BR /&gt;
      "environment" : "sandbox"&lt;BR /&gt;
    }&lt;BR /&gt;
  },&lt;BR /&gt;
  "Profile_2" : {&lt;BR /&gt;
    "systemItemStatus" : "ENABLED",&lt;BR /&gt;
    "environment" : "UAT",&lt;BR /&gt;
    "alwaysPINRequired" : "false"&lt;BR /&gt;
  }&lt;BR /&gt;
}.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:19:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390133#M99256</guid>
      <dc:creator>nareshinsvu</dc:creator>
      <dc:date>2020-09-30T01:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Json and non-json data from single event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390134#M99257</link>
      <description>&lt;P&gt;@nareshinsvu can you try the following rex with your current data?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourCurrentSearch&amp;gt;
| rex "Command response is(?ms)(?&amp;lt;_raw&amp;gt;.*)"
| spath
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ideally, if you do not need the text before JSON, you can drop the same using Heavy Forwarder or Indexer layer, so that &lt;BR /&gt;
1) You index only required data hence save license&lt;BR /&gt;
2) Have indexed_extraction enabled for JSON data so that you can use tstast for better performance.&lt;/P&gt;

&lt;P&gt;Following is a run anywhere example based on the sample data provided.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="2019-06-11_00:06:53.356 [https-openssl-apr-443-exec-70] DEBUG c.audit.AuditingAspect - Testing Command response is
{
\"Response\" : {
\"status\" : \"ACCEPTED\",
\"credential\" : {
\"username\" : \"TestOnline\",
\"failedLoginAttempts\" : 0,
\"failedPwdResetAttempts\" : 0,
\"passwordSecurity\" : 1,
\"type\" : \"APPLICATION\"
},
\"appliactionCredential\" : {
\"username\" : \"Testlogin\",
\"failedLoginAttempts\" : 0,
\"failedPwdResetAttempts\" : 0,
\"passwordSecurity\" : 1,
\"type\" : \"APPLICATION\"
},
\"successful\" : true,
\"userId\" : 00001
},
\"code\" : \"00\",
\"description\" : \"ACCEPTED\",
\"auditId\" : \"audit123\",
\"messageId\" : \"message123\",
\"txnTime\" : 1560175613200,
},
\"Profile\" : {
\"systemItemStatus\" : \"ENABLED\",
\"environment\" : \"sandbox\"
}
},
\"Profile_2\" : {
\"systemItemStatus\" : \"ENABLED\",
\"environment\" : \"UAT\",
\"alwaysPINRequired\" : \"false\"
}
}"
| rex "Command response is(?ms)(?&amp;lt;_raw&amp;gt;.*)"
| spath
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jul 2019 03:03:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390134#M99257</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-07-17T03:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Json and non-json data from single event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390135#M99258</link>
      <description>&lt;P&gt;@niketnilay - Awesome. It worked. Yes the requirement is bit wierd. I need to capture few data from this JSON and also I need to capture few more data from outside JSON (normal text lines). And I have to do a transaction command on all these lines.&lt;/P&gt;

&lt;P&gt;So, I couldn't just extract JSON fileds extraction during forwarding.&lt;/P&gt;

&lt;P&gt;You mentioned about 1) saving license. Is that by extracting only the json fields instead of full json?&lt;BR /&gt;
2) tstats and saving performance - Yes, but complex - as i mentioned, I also need to capture "Testing" word before the JSON line. Any easy way to extract that and assign a column in the result?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 04:43:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390135#M99258</guid>
      <dc:creator>nareshinsvu</dc:creator>
      <dc:date>2019-07-17T04:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Json and non-json data from single event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390136#M99259</link>
      <description>&lt;P&gt;@nareshinsvu &lt;/P&gt;

&lt;P&gt;1) If you drop unwanted text you will be indexing less amount of data. Hence save license accordingly. However, seems like you need to extract &lt;CODE&gt;Testing&lt;/CODE&gt; from regex pattern as well. So, may not be applicable for you.&lt;BR /&gt;
2) Please try the following regex which extracts &lt;CODE&gt;myField&lt;/CODE&gt; with &lt;CODE&gt;Testing&lt;/CODE&gt;. Since regular expression will be strictly based on the pattern in your data, you would need to tweak this and test on regex101.com. I have saved the sample data at the following location: &lt;A href="https://regex101.com/r/GCzdbZ/1"&gt;https://regex101.com/r/GCzdbZ/1&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "\] DEBUG ([^\s]+)\s+-\s+(?&amp;lt;myField&amp;gt;[^\s]+)\sCommand response is(?ms)(?&amp;lt;_raw&amp;gt;.*)" 
| spath
|  table myField *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Do accept/up-vote the answer if your issue is resolved!&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 15:46:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Extract-Json-and-non-json-data-from-single-event/m-p/390136#M99259</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-07-17T15:46:08Z</dc:date>
    </item>
  </channel>
</rss>

