<?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 How to search in a JSON array of hashes? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205432#M59727</link>
    <description>&lt;P&gt;I have a JSON entry as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ [-] 
        name:  change_user_access 
        parameters: [ [-] 
         { [+] 
         } 
         { [-] 
            name:  target_user 
            value:  me@corp.com 
         } 
         { [+] 
         } 
         { [+] 
         } 
         { [-] 
            name:  owner 
            value:  peter@corp.com 
         } 
         { [+] 
         } 
         { [+] 
         } 
         { [+] 
         } 
       ] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm trying to find a way to get only those events where:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;name == "change_user_access"&lt;/LI&gt;
&lt;LI&gt;owner == "*@corp.com"&lt;/LI&gt;
&lt;LI&gt;target_user != "*@corp.com"&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;The problem is that I don't know how to request something like: 'if name="owner" and value="*@corp.com" in the same hash'.&lt;BR /&gt;
Any ideas?&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 09:55:38 GMT</pubDate>
    <dc:creator>jselvi</dc:creator>
    <dc:date>2020-09-29T09:55:38Z</dc:date>
    <item>
      <title>How to search in a JSON array of hashes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205432#M59727</link>
      <description>&lt;P&gt;I have a JSON entry as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ [-] 
        name:  change_user_access 
        parameters: [ [-] 
         { [+] 
         } 
         { [-] 
            name:  target_user 
            value:  me@corp.com 
         } 
         { [+] 
         } 
         { [+] 
         } 
         { [-] 
            name:  owner 
            value:  peter@corp.com 
         } 
         { [+] 
         } 
         { [+] 
         } 
         { [+] 
         } 
       ] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm trying to find a way to get only those events where:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;name == "change_user_access"&lt;/LI&gt;
&lt;LI&gt;owner == "*@corp.com"&lt;/LI&gt;
&lt;LI&gt;target_user != "*@corp.com"&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;The problem is that I don't know how to request something like: 'if name="owner" and value="*@corp.com" in the same hash'.&lt;BR /&gt;
Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:55:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205432#M59727</guid>
      <dc:creator>jselvi</dc:creator>
      <dc:date>2020-09-29T09:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to search in a JSON array of hashes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205433#M59728</link>
      <description>&lt;P&gt;to be clear, do you wanna index only events with these fields or this is already indexed and you want to extract events that has these values?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 13:51:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205433#M59728</guid>
      <dc:creator>axl88</dc:creator>
      <dc:date>2016-06-09T13:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to search in a JSON array of hashes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205434#M59729</link>
      <description>&lt;P&gt;This is already indexed. I want to extract those events and create an alert.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 13:54:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205434#M59729</guid>
      <dc:creator>jselvi</dc:creator>
      <dc:date>2016-06-09T13:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to search in a JSON array of hashes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205435#M59730</link>
      <description>&lt;P&gt;See if the following helps. Please note I'm assuming you have separated events. If that's not the case please provide more information about your JSON.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval _raw = "{ [-] 
         name:  change_user_access 
         parameters: [ [-] 
          { [+] 
          } 
          { [-] 
             name:  target_user 
             value:  me@corp.com 
          } 
          { [+] 
          } 
          { [+] 
          } 
          { [-] 
             name:  owner 
             value:  peter@corp.com 
          } 
          { [+] 
          } 
          { [+] 
          } 
          { [+] 
          } 
        ] "
| regex _raw = "(?msi)name:  change_user_access.+name:  owner \s+value:  peter@corp.com"
| regex _raw != "(?msi)name:  target_user \s+value:  [^\s@]+@corp.com"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;EDIT&lt;/STRONG&gt;&lt;BR /&gt;
Worst case simply extract your JSON with &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath"&gt;spath&lt;/A&gt; and filter with search or where afterwards.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 14:02:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205435#M59730</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-06-09T14:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to search in a JSON array of hashes?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205436#M59731</link>
      <description>&lt;P&gt;I do these type of alerting via field-extractions feature. I write my regex for each field I want to extract and use these fields for alert conditionals. Moreover, it is easier to maintain since all your extractions are saved in settings. Also, I personally don't like having lines of command in my Splunk searches. &lt;/P&gt;

&lt;P&gt;1) in extracted field write your regex with lookahead/lookbehind and name it with appropriate name. in your case, you should look for existence of change_user_access then look for other fields extracted. Your regex should look like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?:Name\s\:)(?P&amp;lt;top_in_hierarcy&amp;gt;[^\-]+?)(?=\nParameters)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;2) then you should do the similar for other fields you want to extract. &lt;BR /&gt;
3) when setting up alert, add top_in_hierarcy field above to your search as "top_in_hierarcy=change_user_access" . It will bring only those events and you can work easier with details using other splunk features as well as regex.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:55:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-in-a-JSON-array-of-hashes/m-p/205436#M59731</guid>
      <dc:creator>axl88</dc:creator>
      <dc:date>2020-09-29T09:55:41Z</dc:date>
    </item>
  </channel>
</rss>

