<?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 to filter results based on property inside JSON string? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-results-based-on-property-inside-JSON-string/m-p/614768#M213671</link>
    <description>&lt;P&gt;Periods are considered a special characters in the fieldname. Consider renaming it or encapsulate it in single quotes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename JSON.transaction_id AS transaction_id
| where transaction_id IN (tx_id)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where 'JSON.transaction_id' IN (tx_id)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2022 14:51:39 GMT</pubDate>
    <dc:creator>johnhuang</dc:creator>
    <dc:date>2022-09-27T14:51:39Z</dc:date>
    <item>
      <title>How to filter results based on property inside JSON string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-results-based-on-property-inside-JSON-string/m-p/614764#M213668</link>
      <description>&lt;P&gt;I want to filter the search results based on&amp;nbsp;&lt;STRONG&gt;tx_id&lt;/STRONG&gt; that I extract in the &lt;STRONG&gt;2nd rex. &lt;/STRONG&gt;Meaning only those results that have the transaction_id same as the tx_id&lt;STRONG&gt;.&amp;nbsp;&lt;/STRONG&gt;I tried the where clause but it doesn't work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;{search_results}

| rex field= MESSAGE "(?&amp;lt;JSON&amp;gt;\{.*\})"

| rex field= MESSAGE "Published Event for txn_id (?&amp;lt;tx_id&amp;gt;\w+)"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{search_results}

| rex field= MESSAGE "(?&amp;lt;JSON&amp;gt;\{.*\})"

| rex field= MESSAGE "Published Event for txn_id (?&amp;lt;tx_id&amp;gt;\w+)"

| where JSON.transaction_id in (tx_id)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 14:22:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-results-based-on-property-inside-JSON-string/m-p/614764#M213668</guid>
      <dc:creator>ghostrider</dc:creator>
      <dc:date>2022-09-27T14:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter results based on property inside JSON string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-results-based-on-property-inside-JSON-string/m-p/614768#M213671</link>
      <description>&lt;P&gt;Periods are considered a special characters in the fieldname. Consider renaming it or encapsulate it in single quotes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename JSON.transaction_id AS transaction_id
| where transaction_id IN (tx_id)​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where 'JSON.transaction_id' IN (tx_id)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 14:51:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-results-based-on-property-inside-JSON-string/m-p/614768#M213671</guid>
      <dc:creator>johnhuang</dc:creator>
      <dc:date>2022-09-27T14:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter results based on property inside JSON string?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-results-based-on-property-inside-JSON-string/m-p/614787#M213675</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249848"&gt;@ghostrider&lt;/a&gt;&amp;nbsp;A reminder that "&lt;SPAN&gt;it doesn't work" conveys very little information and should be avoided.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You also forgot to say what is the content of the JSON and how the content relate to your requirement. &amp;nbsp;I speculate that this extracted field would contain a conformant JSON object that happens to have a key&amp;nbsp;transaction_id. &amp;nbsp;If this is the case, you need to first extract the key from JSON first, with&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath" target="_blank" rel="noopener"&gt;spath&lt;/A&gt;. &amp;nbsp;In addition, why do you choose to use IN instead of ==? &amp;nbsp;If you expect tx_id to have multiple values in that string, you need to use maxmatch=0 in rex. &amp;nbsp;Third, you must not leave space between field= and MESSAGE.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In the following example, I'll assume that there is only one tx_id in each MESSAGE.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{search_results}
| rex field=MESSAGE "(?&amp;lt;JSON&amp;gt;\{.*\})"
| rex field=MESSAGE "Published Event for txn_id (?&amp;lt;tx_id&amp;gt;\w+)"
| spath input=JSON
| where transaction_id == tx_id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if your data is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;MESSAGE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Published Event for txn_id abc123 blah {"transaction_id":"abc123","foo":"bar"}&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Published Event for txn_id cde456 blah {"transaction_id":"fgh789","foo":"bar"}&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The above should give you&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;JSON&lt;/TD&gt;&lt;TD&gt;MESSAGE&lt;/TD&gt;&lt;TD&gt;foo&lt;/TD&gt;&lt;TD&gt;transaction_id&lt;/TD&gt;&lt;TD&gt;tx_id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;{"transaction_id":"abc123","foo":"bar"}&lt;/TD&gt;&lt;TD&gt;Published Event for txn_id abc123 blah {"transaction_id":"abc123","foo":"bar"}&lt;/TD&gt;&lt;TD&gt;bar&lt;/TD&gt;&lt;TD&gt;abc123&lt;/TD&gt;&lt;TD&gt;abc123&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;In other words, the second message is excluded.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 17:11:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-results-based-on-property-inside-JSON-string/m-p/614787#M213675</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-09-27T17:11:35Z</dc:date>
    </item>
  </channel>
</rss>

