<?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: Correlation of 2 fields within json array in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/Correlation-of-2-fields-within-json-array/m-p/509996#M2712</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223785"&gt;@galsegal&lt;/a&gt;&amp;nbsp;Is this what you're after ?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{
    \"Features\": [
        { 
            \"anomaly\": false,
            \"id\" : 25,
            \"name\" : \"service\"
        },
        { 
            \"anomaly\": true,
            \"id\" : 23,
            \"name\" : \"location\"
        },
        { 
            \"anomaly\": false,
            \"id\" : 24,
            \"name\" : \"ip\"
        },
        { 
            \"anomaly\": false,
            \"id\" : 27,
            \"name\" : \"time\"
        }
    ]
}"
| rename COMMENT AS "The code below is what is needed. First extract each value from the tree, than we group and split them based on how they are related." 
| spath path="Features{}.anomaly" output=anomaly
| spath path="Features{}.id" output=id
| spath path="Features{}.name" output=name
| eval x = mvzip(mvzip(id, anomaly, "\n"), name, "\n")
| mvexpand x
| eval x=split(x,"\n")
| eval ID = mvindex(x, 0)
| eval Name = mvindex(x, 1)
| eval Anomaly = mvindex(x, 2)
| stats values(Name) as Name values(Anomaly) as Anomaly by ID&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 20 Jul 2020 09:20:59 GMT</pubDate>
    <dc:creator>anmolpatel</dc:creator>
    <dc:date>2020-07-20T09:20:59Z</dc:date>
    <item>
      <title>Correlation of 2 fields within json array</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Correlation-of-2-fields-within-json-array/m-p/509990#M2710</link>
      <description>&lt;P&gt;Hey All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to do is to build a search query that correlates between fields like in the below example:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="galsegal_0-1595233816225.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/9781i13A4A00FF35D80FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="galsegal_0-1595233816225.png" alt="galsegal_0-1595233816225.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I need that where message.anomaly.features{}.anomaly has a true value, then to output a new field with the corresponding fields below - 23, location (Even only one of them is good for me)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I accomplish that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 08:32:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Correlation-of-2-fields-within-json-array/m-p/509990#M2710</guid>
      <dc:creator>galsegal</dc:creator>
      <dc:date>2020-07-20T08:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Correlation of 2 fields within json array</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Correlation-of-2-fields-within-json-array/m-p/509996#M2712</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/223785"&gt;@galsegal&lt;/a&gt;&amp;nbsp;Is this what you're after ?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{
    \"Features\": [
        { 
            \"anomaly\": false,
            \"id\" : 25,
            \"name\" : \"service\"
        },
        { 
            \"anomaly\": true,
            \"id\" : 23,
            \"name\" : \"location\"
        },
        { 
            \"anomaly\": false,
            \"id\" : 24,
            \"name\" : \"ip\"
        },
        { 
            \"anomaly\": false,
            \"id\" : 27,
            \"name\" : \"time\"
        }
    ]
}"
| rename COMMENT AS "The code below is what is needed. First extract each value from the tree, than we group and split them based on how they are related." 
| spath path="Features{}.anomaly" output=anomaly
| spath path="Features{}.id" output=id
| spath path="Features{}.name" output=name
| eval x = mvzip(mvzip(id, anomaly, "\n"), name, "\n")
| mvexpand x
| eval x=split(x,"\n")
| eval ID = mvindex(x, 0)
| eval Name = mvindex(x, 1)
| eval Anomaly = mvindex(x, 2)
| stats values(Name) as Name values(Anomaly) as Anomaly by ID&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 Jul 2020 09:20:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Correlation-of-2-fields-within-json-array/m-p/509996#M2712</guid>
      <dc:creator>anmolpatel</dc:creator>
      <dc:date>2020-07-20T09:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Correlation of 2 fields within json array</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Correlation-of-2-fields-within-json-array/m-p/510012#M2715</link>
      <description>&lt;P&gt;This was not 100% the solution but it indeed got me there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you very much, sir.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2020 10:16:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Correlation-of-2-fields-within-json-array/m-p/510012#M2715</guid>
      <dc:creator>galsegal</dc:creator>
      <dc:date>2020-07-20T10:16:44Z</dc:date>
    </item>
  </channel>
</rss>

