<?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 search JSON data for specific values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626492#M217749</link>
    <description>&lt;P&gt;Show us the full search because from what you're saying it should filter only those events you want.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jan 2023 23:14:14 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2023-01-09T23:14:14Z</dc:date>
    <item>
      <title>How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626481#M217744</link>
      <description>&lt;P&gt;I have a JSON file I am trying to search for a specific value - EventType=GoodMail - and then pull the values from another field -&amp;nbsp;{}.MessageCount. I have the following search to pull back the&amp;nbsp;EventType of just GoodMail:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="mail_reports" 
| spath 
| mvexpand "{}.EventType" 
| search {}.EventType=GoodMail&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if I add this on to the end of the search:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats values "{}.MessageCount"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get - "&lt;SPAN&gt;Error in 'stats' command: The argument '{}.MessageCount' is invalid."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How do I modify the search to pull back the values for&amp;nbsp;{}.MessageCount'?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thx&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2023 21:41:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626481#M217744</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2023-01-09T21:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626482#M217745</link>
      <description>&lt;P&gt;JSON file data is as follows&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "GoodMail",
        "Direction":  "Inbound",
        "MessageCount":  393253,
        "Index":  0
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "GoodMail",
        "Direction":  "Outbound",
        "MessageCount":  96305,
        "Index":  2
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "EmailMalware",
        "Direction":  "Inbound",
        "MessageCount":  34,
        "Index":  3
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "EmailPhish",
        "Direction":  "Inbound",
        "MessageCount":  9678,
        "Index":  4
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "EmailPhish",
        "Direction":  "Outbound",
        "MessageCount":  111,
        "Index":  5
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "SpamDetections",
        "Direction":  "Inbound",
        "MessageCount":  55265,
        "Index":  6
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "SpamDetections",
        "Direction":  "Outbound",
        "MessageCount":  1155,
        "Index":  7
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "EdgeBlockSpam",
        "Direction":  "Inbound",
        "MessageCount":  614454,
        "Index":  8
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "TransportRules",
        "Direction":  "Inbound",
        "MessageCount":  24843,
        "Index":  9
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "EdgeBlockSpam",
        "Direction":  "Outbound",
        "MessageCount":  722,
        "Index":  10
    },
    {
        "Organization":  "foo.foomail.com",
        "Date":  "2023-01-08",
        "EventType":  "TransportRules",
        "Direction":  "Outbound",
        "MessageCount":  37537,
        "Index":  11
    }
]&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 09 Jan 2023 21:44:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626482#M217745</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2023-01-09T21:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626483#M217746</link>
      <description>&lt;P&gt;Assuming you do have such field, as this is an argument to aggregation function, you need to enclose it in parentheses&lt;/P&gt;&lt;PRE&gt;| stats values('{}.MessageCount')&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jan 2023 21:46:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626483#M217746</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-01-09T21:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626484#M217747</link>
      <description>&lt;P&gt;Thx for the reply&lt;/P&gt;&lt;P&gt;I added the following, but the issue is I'm getting all the MessageCount values back and not just for&amp;nbsp;{}.EventType=GoodMail&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats values("{}.MessageCount")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2023 22:00:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626484#M217747</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2023-01-09T22:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626492#M217749</link>
      <description>&lt;P&gt;Show us the full search because from what you're saying it should filter only those events you want.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2023 23:14:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626492#M217749</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-01-09T23:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626534#M217764</link>
      <description>&lt;P&gt;The raw data is an array, so you need to use &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Mvexpand" target="_blank" rel="noopener"&gt;mvexpand&lt;/A&gt;. &amp;nbsp;Instead of just running spath, first extract each array element of {}.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path={}
| mvexpand {}
| spath input={}
| where EventType == "GoodMail"
| stats values(MessageCount)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will give you&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;values(MessageCount)&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;393253&lt;/DIV&gt;&lt;DIV class=""&gt;96305&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I'm not sure why values(MessageCount) would be useful, though. &amp;nbsp;Did you mean to add them together? &amp;nbsp;Like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path={}
| mvexpand {}
| spath input={}
| where EventType == "GoodMail"
| stats sum(MessageCount)​​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;sum(MessageCount)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;489558&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 10 Jan 2023 08:17:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626534#M217764</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-01-10T08:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626564#M217771</link>
      <description>&lt;P&gt;OK. That's a bit more clear. You have to understand one thing - Splunk treats events as collection of fields, it doesn't get much into the structure of json or XML. If it parses them, it "flattens" them effectively.&lt;/P&gt;&lt;P&gt;So if you do a "global" spath on an event, as you were doing, it will combine into one multivalued field all values of multiple instances of the same field from various sub structures or subarrays.&lt;/P&gt;&lt;P&gt;The only thing that you can do, as &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; did is to split your json into separate strings which will then be treated as separate events because otherwise you'll just get lists of values contained in various structures within the original json structure but without any relationship between them. So your condition matching EventType="GoodMail" was correctly (as per how Splunk works) matching your whole original json structure, not - as you wanted it - a specific substructure contained therein.&lt;/P&gt;&lt;P&gt;&amp;nbsp;I hope I didn't make it sound too complicated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 10:45:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626564#M217771</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-01-10T10:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626599#M217788</link>
      <description>&lt;P&gt;TYVM for breaking this down as it's greatly appreciated.&lt;/P&gt;&lt;P&gt;I understand what the following two commands do more clearly:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path={}
| mvexpand {}&lt;/LI-CODE&gt;&lt;P&gt;Can you please expand on the following command?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath input={}&lt;/LI-CODE&gt;&lt;P&gt;Is that simply saying to look inside the {} brackets for the data?&lt;/P&gt;&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 13:57:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626599#M217788</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2023-01-10T13:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626600#M217789</link>
      <description>&lt;P&gt;TYVM for the reply and information as it really helped me understand how to use spath much better.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 13:58:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626600#M217789</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2023-01-10T13:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626715#M217826</link>
      <description>&lt;P&gt;That is correct. &amp;nbsp;In &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath" target="_blank" rel="noopener"&gt;spath&lt;/A&gt; command, input introduces a field to be used as source. (I which extract, multikv, and so on had a similar setting, too.) &amp;nbsp;In this context, {} has no special meaning except a string representing that field name that the previous spath command extracted.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 07:24:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626715#M217826</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-01-11T07:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to search JSON data for specific values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626782#M217840</link>
      <description>&lt;P&gt;TYVM for the info - greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 13:18:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-JSON-data-for-specific-values/m-p/626782#M217840</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2023-01-11T13:18:15Z</dc:date>
    </item>
  </channel>
</rss>

