<?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: Help in extract data using rex in Splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-in-extract-data-using-rex-in-Splunk/m-p/690748#M235252</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/260633"&gt;@anil1219&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;this seeems to be a json format so you could use the INDEXED_EXTRACTION = JSON in the sourcetype definition in props.conf (&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.2.1/Admin/Propsconf" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.2.1/Admin/Propsconf&lt;/A&gt;) or the spath command (&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.2.1/SearchReference/Spath" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.2.1/SearchReference/Spath&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;Otherwise, you could use a regex like the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; rex "\"PaymentType\":\"(?&amp;lt;PaymentType&amp;gt;[^\"]+)"&lt;/LI-CODE&gt;&lt;P&gt;the you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/VEeiyG/1" target="_blank"&gt;https://regex101.com/r/VEeiyG/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jun 2024 17:57:09 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2024-06-14T17:57:09Z</dc:date>
    <item>
      <title>Help in extract data using rex in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-in-extract-data-using-rex-in-Splunk/m-p/690747#M235251</link>
      <description>&lt;P&gt;I have 2 records for PaymentType as send and receive. I would like to extract PaymentType as receive only so that I can further compare.&lt;/P&gt;&lt;P&gt;Could you please let me know how do I can extract PaymentType as receive only.&lt;/P&gt;&lt;P&gt;transaction: {"version":1,"status":"approved","identifier":"0c4240e0-2c2c-6427-fb1f-71131029cd89","amount":"[REDACTED]","transactionAmount":"[REDACTED]","timestamp":"2024-06-13T04:29:20.673+0000","statusChangedTimestamp":"2024-06-13T04:29:56.337+0000","type":"payment","transferIdentifier":"cded3395-38f9-4258-90a5-9269abfa5536","currencyCode":"USD","PaymentType":"receive","senderHandle":"[REDACTED]","recipientHandle":"[REDACTED]","fees":[],"transferMode":"contact"}&lt;/P&gt;&lt;P&gt;transaction: {"version":1,"status":"approved","identifier":"0c4240e0-2c2c-6427-fb1f-71131029cd89","amount":"[REDACTED]","transactionAmount":"[REDACTED]","timestamp":"2024-06-13T04:29:20.673+0000","statusChangedTimestamp":"2024-06-13T04:29:56.337+0000","type":"payment","transferIdentifier":"cded3395-38f9-4258-90a5-9269abfa5536","currencyCode":"USD","PaymentType":"send","senderHandle":"[REDACTED]","recipientHandle":"[REDACTED]","fees":[],"transferMode":"contact"}&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 17:10:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-in-extract-data-using-rex-in-Splunk/m-p/690747#M235251</guid>
      <dc:creator>anil1219</dc:creator>
      <dc:date>2024-06-14T17:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help in extract data using rex in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-in-extract-data-using-rex-in-Splunk/m-p/690748#M235252</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/260633"&gt;@anil1219&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;this seeems to be a json format so you could use the INDEXED_EXTRACTION = JSON in the sourcetype definition in props.conf (&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.2.1/Admin/Propsconf" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.2.1/Admin/Propsconf&lt;/A&gt;) or the spath command (&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.2.1/SearchReference/Spath" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.2.1/SearchReference/Spath&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;Otherwise, you could use a regex like the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; rex "\"PaymentType\":\"(?&amp;lt;PaymentType&amp;gt;[^\"]+)"&lt;/LI-CODE&gt;&lt;P&gt;the you can test at&amp;nbsp;&lt;A href="https://regex101.com/r/VEeiyG/1" target="_blank"&gt;https://regex101.com/r/VEeiyG/1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 17:57:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-in-extract-data-using-rex-in-Splunk/m-p/690748#M235252</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2024-06-14T17:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help in extract data using rex in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-in-extract-data-using-rex-in-Splunk/m-p/690773#M235266</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;points out, the data you illustrated is suspiciously close to JSON. &amp;nbsp;Are you sure that your data is not like this instead?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"transaction": {"version":1,"status":"approved","identifier":"0c4240e0-2c2c-6427-fb1f-71131029cd89","amount":"[REDACTED]","transactionAmount":"[REDACTED]","timestamp":"2024-06-13T04:29:20.673+0000","statusChangedTimestamp":"2024-06-13T04:29:56.337+0000","type":"payment","transferIdentifier":"cded3395-38f9-4258-90a5-9269abfa5536","currencyCode":"USD","PaymentType":"receive","senderHandle":"[REDACTED]","recipientHandle":"[REDACTED]","fees":[],"transferMode":"contact"}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or is it possible that you are simply illustrating an extracted field named &lt;U&gt;transaction&lt;/U&gt;&amp;nbsp;whose values are&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"version":1,"status":"approved","identifier":"0c4240e0-2c2c-6427-fb1f-71131029cd89","amount":"[REDACTED]","transactionAmount":"[REDACTED]","timestamp":"2024-06-13T04:29:20.673+0000","statusChangedTimestamp":"2024-06-13T04:29:56.337+0000","type":"payment","transferIdentifier":"cded3395-38f9-4258-90a5-9269abfa5536","currencyCode":"USD","PaymentType":"receive","senderHandle":"[REDACTED]","recipientHandle":"[REDACTED]","fees":[],"transferMode":"contact"}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{"version":1,"status":"approved","identifier":"0c4240e0-2c2c-6427-fb1f-71131029cd89","amount":"[REDACTED]","transactionAmount":"[REDACTED]","timestamp":"2024-06-13T04:29:20.673+0000","statusChangedTimestamp":"2024-06-13T04:29:56.337+0000","type":"payment","transferIdentifier":"cded3395-38f9-4258-90a5-9269abfa5536","currencyCode":"USD","PaymentType":"send","senderHandle":"[REDACTED]","recipientHandle":"[REDACTED]","fees":[],"transferMode":"contact"}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If not, your developers are really doing a deservice to everyone downstream, not just Splunkers. &amp;nbsp;But if raw data &amp;nbsp;is indeed as you originally posted, you can first extract the valid JSON into a field, let's call it &lt;U&gt;transaction&lt;/U&gt;, then extract key-value pairs from this object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "transaction: *(?&amp;lt;transaction&amp;gt;{.+)"
| fromjson transaction&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what you should get&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PaymentType&lt;/TD&gt;&lt;TD&gt;amount&lt;/TD&gt;&lt;TD&gt;currencyCode&lt;/TD&gt;&lt;TD&gt;fees&lt;/TD&gt;&lt;TD&gt;identifier&lt;/TD&gt;&lt;TD&gt;recipientHandle&lt;/TD&gt;&lt;TD&gt;senderHandle&lt;/TD&gt;&lt;TD&gt;status&lt;/TD&gt;&lt;TD&gt;statusChangedTimestamp&lt;/TD&gt;&lt;TD&gt;timestamp&lt;/TD&gt;&lt;TD&gt;transactionAmount&lt;/TD&gt;&lt;TD&gt;transferIdentifier&lt;/TD&gt;&lt;TD&gt;transferMode&lt;/TD&gt;&lt;TD&gt;type&lt;/TD&gt;&lt;TD&gt;version&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;receive&lt;/TD&gt;&lt;TD&gt;[REDACTED]&lt;/TD&gt;&lt;TD&gt;USD&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0c4240e0-2c2c-6427-fb1f-71131029cd89&lt;/TD&gt;&lt;TD&gt;[REDACTED]&lt;/TD&gt;&lt;TD&gt;[REDACTED]&lt;/TD&gt;&lt;TD&gt;approved&lt;/TD&gt;&lt;TD&gt;2024-06-13T04:29:56.337+0000&lt;/TD&gt;&lt;TD&gt;2024-06-13T04:29:20.673+0000&lt;/TD&gt;&lt;TD&gt;[REDACTED]&lt;/TD&gt;&lt;TD&gt;cded3395-38f9-4258-90a5-9269abfa5536&lt;/TD&gt;&lt;TD&gt;contact&lt;/TD&gt;&lt;TD&gt;payment&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;send&lt;/TD&gt;&lt;TD&gt;[REDACTED]&lt;/TD&gt;&lt;TD&gt;USD&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0c4240e0-2c2c-6427-fb1f-71131029cd89&lt;/TD&gt;&lt;TD&gt;[REDACTED]&lt;/TD&gt;&lt;TD&gt;[REDACTED]&lt;/TD&gt;&lt;TD&gt;approved&lt;/TD&gt;&lt;TD&gt;2024-06-13T04:29:56.337+0000&lt;/TD&gt;&lt;TD&gt;2024-06-13T04:29:20.673+0000&lt;/TD&gt;&lt;TD&gt;[REDACTED]&lt;/TD&gt;&lt;TD&gt;cded3395-38f9-4258-90a5-9269abfa5536&lt;/TD&gt;&lt;TD&gt;contact&lt;/TD&gt;&lt;TD&gt;payment&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is an emulation you can play with and compare with real data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data = mvappend("transaction: {\"version\":1,\"status\":\"approved\",\"identifier\":\"0c4240e0-2c2c-6427-fb1f-71131029cd89\",\"amount\":\"[REDACTED]\",\"transactionAmount\":\"[REDACTED]\",\"timestamp\":\"2024-06-13T04:29:20.673+0000\",\"statusChangedTimestamp\":\"2024-06-13T04:29:56.337+0000\",\"type\":\"payment\",\"transferIdentifier\":\"cded3395-38f9-4258-90a5-9269abfa5536\",\"currencyCode\":\"USD\",\"PaymentType\":\"receive\",\"senderHandle\":\"[REDACTED]\",\"recipientHandle\":\"[REDACTED]\",\"fees\":[],\"transferMode\":\"contact\"}",
"transaction: {\"version\":1,\"status\":\"approved\",\"identifier\":\"0c4240e0-2c2c-6427-fb1f-71131029cd89\",\"amount\":\"[REDACTED]\",\"transactionAmount\":\"[REDACTED]\",\"timestamp\":\"2024-06-13T04:29:20.673+0000\",\"statusChangedTimestamp\":\"2024-06-13T04:29:56.337+0000\",\"type\":\"payment\",\"transferIdentifier\":\"cded3395-38f9-4258-90a5-9269abfa5536\",\"currencyCode\":\"USD\",\"PaymentType\":\"send\",\"senderHandle\":\"[REDACTED]\",\"recipientHandle\":\"[REDACTED]\",\"fees\":[],\"transferMode\":\"contact\"}")
| mvexpand data
| rename data AS _raw
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 23:42:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-in-extract-data-using-rex-in-Splunk/m-p/690773#M235266</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-06-14T23:42:53Z</dc:date>
    </item>
  </channel>
</rss>

