<?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: Pulling Data from Nested JSON Fields based on Field Value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-pull-data-from-Nested-JSON-Fields-based-on-Field-Value/m-p/613157#M213095</link>
    <description>&lt;P&gt;Here's an example using your base data. I added a 4th file, also attached to show that it works with possible multiple 'attached' files.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{
 \"messageParts\": [
{
\"contentType\":\"image/png\",
\"disposition\":\"attached\",
\"filename\":\"example.png\",
\"md5\":\"xxyy\",
\"sha256\":\"xxyy\"
},
{
\"contentType\":\"text/html\",
\"disposition\":\"inline\",
\"filename\":\"text.html\",
\"md5\":\"xxyy\",
\"sha256\":\"xxyy\"
},
{
\"contentType\":\"text/plain\",
\"disposition\":\"inline\",
\"filename\":\"text.txt\",
\"md5\":\"xxyy\",
\"sha256\":\"xxyy\"
},
{
\"contentType\":\"text/plain\",
\"disposition\":\"attached\",
\"filename\":\"bla.txt\",
\"md5\":\"nnnn\",
\"sha256\":\"zzzz\"
}
]
}
"
| spath
| rename messageParts{}.* as *
| foreach 0 1 2 3 4 5 6 7 8 9 10 [ eval isAttach=if(mvindex(disposition, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)="attached", 1, 0),  file=if(isAttach=1, mvappend(file, mvindex(filename, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)), file), hash_md5=if(isAttach=1, mvappend(hash_md5, mvindex(md5, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)), hash_md5), hash_sha256=if(isAttach=1, mvappend(hash_sha256, mvindex(sha256, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)), hash_sha256) ]&lt;/LI-CODE&gt;&lt;P&gt;Up to the spath is setting up the data example. The foreach 0 1 2... is simply creating a loop for 0-10, so supporting 11 possible filenames - add as many as you want. The returned file, hash_md5 and hash_sha256 will contain the data you need&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2022 00:11:27 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2022-09-15T00:11:27Z</dc:date>
    <item>
      <title>How to pull data from Nested JSON Fields based on Field Value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pull-data-from-Nested-JSON-Fields-based-on-Field-Value/m-p/613136#M213088</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm working on creating automated alerts from an email security vendor and would like for them to only include the names of files/attachments which have the "attached" disposition within a nested JSON structure. The example below shows what I'm talking about in a limited/trimmed capacity:&lt;BR /&gt;messageParts: [&lt;BR /&gt;{&lt;BR /&gt;contentType: image/png&lt;BR /&gt;disposition: attached&lt;BR /&gt;filename: example.png&lt;BR /&gt;md5: xxyy&lt;BR /&gt;sha256: xxyy&lt;BR /&gt;}&lt;BR /&gt;{&lt;BR /&gt;contentType: text/html&lt;BR /&gt;disposition: inline&lt;BR /&gt;filename: text.html&lt;BR /&gt;md5: xxyy&lt;BR /&gt;sha256: xxyy&lt;BR /&gt;}&lt;BR /&gt;{&lt;BR /&gt;contentType: text/plain&lt;BR /&gt;disposition: inline&lt;BR /&gt;filename: text.txt&lt;BR /&gt;md5: xxyy&lt;BR /&gt;sha256: xxyy&lt;BR /&gt;}&lt;BR /&gt;]&lt;/P&gt;
&lt;P&gt;Essentially I'd like to pull and store the respective "filename" and hash values for when the "disposition" field is "attached" but not "inline". I know this can likely be done using something like spath or mvfind, but I'm not entirely sure how to accomplish it and it's giving me fits.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone who can lend a helping hand would be handsomely rewarded with karma and many well wishes, thanks for taking the time to consider my question!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 14:41:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pull-data-from-Nested-JSON-Fields-based-on-Field-Value/m-p/613136#M213088</guid>
      <dc:creator>cfloquet</dc:creator>
      <dc:date>2022-09-15T14:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Data from Nested JSON Fields based on Field Value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pull-data-from-Nested-JSON-Fields-based-on-Field-Value/m-p/613157#M213095</link>
      <description>&lt;P&gt;Here's an example using your base data. I added a 4th file, also attached to show that it works with possible multiple 'attached' files.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{
 \"messageParts\": [
{
\"contentType\":\"image/png\",
\"disposition\":\"attached\",
\"filename\":\"example.png\",
\"md5\":\"xxyy\",
\"sha256\":\"xxyy\"
},
{
\"contentType\":\"text/html\",
\"disposition\":\"inline\",
\"filename\":\"text.html\",
\"md5\":\"xxyy\",
\"sha256\":\"xxyy\"
},
{
\"contentType\":\"text/plain\",
\"disposition\":\"inline\",
\"filename\":\"text.txt\",
\"md5\":\"xxyy\",
\"sha256\":\"xxyy\"
},
{
\"contentType\":\"text/plain\",
\"disposition\":\"attached\",
\"filename\":\"bla.txt\",
\"md5\":\"nnnn\",
\"sha256\":\"zzzz\"
}
]
}
"
| spath
| rename messageParts{}.* as *
| foreach 0 1 2 3 4 5 6 7 8 9 10 [ eval isAttach=if(mvindex(disposition, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)="attached", 1, 0),  file=if(isAttach=1, mvappend(file, mvindex(filename, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)), file), hash_md5=if(isAttach=1, mvappend(hash_md5, mvindex(md5, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)), hash_md5), hash_sha256=if(isAttach=1, mvappend(hash_sha256, mvindex(sha256, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)), hash_sha256) ]&lt;/LI-CODE&gt;&lt;P&gt;Up to the spath is setting up the data example. The foreach 0 1 2... is simply creating a loop for 0-10, so supporting 11 possible filenames - add as many as you want. The returned file, hash_md5 and hash_sha256 will contain the data you need&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 00:11:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pull-data-from-Nested-JSON-Fields-based-on-Field-Value/m-p/613157#M213095</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-09-15T00:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Data from Nested JSON Fields based on Field Value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-pull-data-from-Nested-JSON-Fields-based-on-Field-Value/m-p/613816#M213316</link>
      <description>&lt;P&gt;I think this works great, havent tested fully yet but it looks right to me.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 18:06:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-pull-data-from-Nested-JSON-Fields-based-on-Field-Value/m-p/613816#M213316</guid>
      <dc:creator>cfloquet</dc:creator>
      <dc:date>2022-09-20T18:06:14Z</dc:date>
    </item>
  </channel>
</rss>

