<?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: Extracting Value from and Event in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745867#M241561</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; and&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;! This is my first real post here, so I appreciate you bearing with me as I may not have provided a complete picture.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;'s answer provided a clear example of how I can use mvfind and mvindex to extract the correct data. The only thing I had to add was a \b word boundary to the mvfind regex, so it wouldn't hit the earlier partial match. Here is the query:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=okta "debugContext.debugData.privilegeGranted"="*"
| eval type_index = mvfind('target{}.type', "CUSTOM_ROLE\b")
| eval "Target Name" = mvindex('target{}.displayName', type_index)
| eval "Target ID" = mvindex('target{}.alternateId', type_index)
| rename actor.displayName as "Actor", description as "Action",
  debugContext.debugData.privilegeGranted as "Role(s)"
| table Time, Actor, Action, "Target Name", "Target ID", Action, "Role(s)"&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 09 May 2025 18:47:06 GMT</pubDate>
    <dc:creator>bill</dc:creator>
    <dc:date>2025-05-09T18:47:06Z</dc:date>
    <item>
      <title>Extracting Value from and Event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745814#M241550</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am looking to add a particular value to an existing search of Okta data. The problem is I don't know how to extract the value which is on the same level as other values. The value I am looking for is "Workflows Administrator". The existing search is:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=okta "debugContext.debugData.privilegeGranted"="*" | rename actor.displayName as "Actor", targetUserDisplayName as "Target Name", targetUserAlternateId as "Target ID", description as "Action", debugContext.debugData.privilegeGranted as "Role(s)" | eval Time = strftime(_time, "%Y-%d-%m %H:%M:%S") | fields - _time | table Time, Actor, Action, "Target Name", "Target ID", Action, "Role(s)"&lt;/LI-CODE&gt;&lt;P&gt;and sample data is&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{ [-]
   actor: { [+]
   }
   authenticationContext: { [+]
   }
   client: { [+]
   }
   debugContext: { [-]
     debugData: { [-]
       privilegeGranted: Application administrator (all), User administrator (all), Help Desk administrator (all)
     }
   }
   device: null
   displayMessage: Grant user privilege
   eventType: user.account.privilege.grant
   legacyEventType: core.user.admin_privilege.granted
   outcome: { [-]
     reason: null
     result: SUCCESS
   }
   published: 2025-05-08T19:30:54.612Z
   request: { [-]
     ipChain: [ [+]
     ]
   }
   securityContext: { [-]
     asNumber: null
     asOrg: null
     domain: null
     isProxy: null
     isp: null
   }
   severity: INFO
   target: [ [-]
     { [-]
       alternateId: jdoe@company.com
       detailEntry: null
       displayName: John Doe
       id: 00umfyv9jwzVvafI71t7
       type: User
     }
     { [-]
       alternateId: unknown
       detailEntry: null
       displayName: Custom role binding added
       id: CUSTOM_ROLE_BINDING_ADDED
       type: CUSTOM_ROLE_BINDING_ADDED
     }
     { [-]
       alternateId: /api/v1/iam/roles/WORKFLOWS_ADMIN
       detailEntry: null
       displayName: Workflows Administrator
       id: WORKFLOWS_ADMIN
       type: CUSTOM_ROLE
     }
     { [-]
       alternateId: /api/v1/iam/resource-sets/WORKFLOWS_IAM_POLICY
       detailEntry: null
       displayName: Workflows Resource Set
       id: WORKFLOWS_IAM_POLICY
       type: RESOURCE_SET
     }
   ]
   transaction: { [+]
   }
   uuid: 2c42-11f0-a9fe
   version: 0
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Any help is appreciated. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 20:56:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745814#M241550</guid>
      <dc:creator>bill</dc:creator>
      <dc:date>2025-05-08T20:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Value from and Event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745816#M241551</link>
      <description>&lt;P&gt;Not totally sure I understand, but if you're trying to get the 3rd array element of target which corresponds to the Workflow admin, then this little snippet will get the JSON for that array element&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval workflow_admin=spath(_raw, "target{}")
| eval workflow_admin=mvmap(workflow_admin, if(tostring(spath('workflow_admin', "displayName"))="Workflows Administrator", 'workflow_admin', null()))&lt;/LI-CODE&gt;&lt;P&gt;There are probably a number of ways of getting at the JSON, but this works.&lt;/P&gt;&lt;P&gt;Here's another way&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval workflow_admin=json_array_to_mv(json_extract(_raw, "target{}"))
| eval workflow_admin=mvmap(workflow_admin, if(tostring(spath('workflow_admin', "displayName"))="Workflows Administrator", 'workflow_admin', null()))&lt;/LI-CODE&gt;&lt;P&gt;Once you have workflow_admin, you can manipulate/extract the fields as needed&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 00:07:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745816#M241551</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-05-09T00:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Value from and Event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745820#M241552</link>
      <description>&lt;P&gt;Before anything, let me first say that when you post JSON event sample, always use "Show raw text" before copying. &amp;nbsp;This helps others help you. &amp;nbsp;Secondly, as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;says, it is really unclear what you are asking. &amp;nbsp;You already know the value "Workflows Administrator". &amp;nbsp;Do you mean to search for this value and display other related key-value pairs? &amp;nbsp;Or do you mean there are other possible values from the 3rd array element of target[] that you want to know how to reach that correct array element?&lt;/P&gt;&lt;P&gt;If former, you need to specify which key-value pairs in that element are of interest. &amp;nbsp;If latter, there are many ways, including a method that does not do "extracting" because Splunk by default has done that for you. &amp;nbsp;But before doing that, you need to use Splunk's flattened-structure notation, not invented names like&amp;nbsp;targetUserDisplayName. (Splunk's notation is target{}.displayName for this one.)&lt;/P&gt;&lt;P&gt;Anyway, assuming the latter,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;already showed you several ways. &amp;nbsp;Here I first present a formulae approach to reach every JSON array node in SPL: &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath" target="_blank" rel="noopener"&gt;spath&lt;/A&gt; + &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Mvexpand" target="_blank" rel="noopener"&gt;mvexpand&lt;/A&gt;. &amp;nbsp;But before I show any code, you need to perform the most critical task: &amp;nbsp;to understand how that element is different from other elements in the same array, all of them having a key &lt;U&gt;displayName&lt;/U&gt;. &amp;nbsp;In order to make this determination, you need to carefully study the data. &amp;nbsp;The differentiating factor among those elements is the JSON key &lt;U&gt;type&lt;/U&gt;&amp;nbsp;in that array. &amp;nbsp;So, you would be looking for the element whose &lt;U&gt;type&lt;/U&gt; is &lt;FONT face="courier new,courier"&gt;CUSTOM_ROLE&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=okta "debugContext.debugData.privilegeGranted"="*"
| fields - target{}.*
| spath path=target{}
| mvexpand target{}
| spath input=target{}
| where type == "CUSTOM_ROLE"
| rename actor.displayName as "Actor", displayName as "Target Name",
  alternateId as "Target ID", description as "Action",
  debugContext.debugData.privilegeGranted as "Role(s)"
| table Time, Actor, Action, "Target Name", "Target ID", Action, "Role(s)"&lt;/LI-CODE&gt;&lt;P&gt;With this approach, you can handle any JSON array.&lt;/P&gt;&lt;P&gt;If you don't want to (re)extract everything in the array - there are occasions when mvexpand can be too expensive, here is a quirky method that can do the same thing: capture the value of target{}.displayName and target{}.alternateId corresponding to target{}.type of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CUSTOM_ROLE&lt;/FONT&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=okta "debugContext.debugData.privilegeGranted"="*"
| eval type_index = mvfind('target{}.type', "CUSTOM_ROLE")
| eval "Target Name" = mvindex('target{}.displayName', type_index)
| eval "Target ID" = mvindex('target{}.alternateId', type_index)
| rename actor.displayName as "Actor", description as "Action",
  debugContext.debugData.privilegeGranted as "Role(s)"
| table Time, Actor, Action, "Target Name", "Target ID", Action, "Role(s)"&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 09 May 2025 02:33:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745820#M241552</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2025-05-09T02:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Value from and Event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745826#M241553</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/261058"&gt;@bill&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you're looking to see if the user is a&amp;nbsp;Workflows Administrator then the following should work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval isAdmin=IF(typeof(mvfind('target{}.displayName', "Workflows Administrator"))=="Number","Yes","No")&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":glowing_star:"&gt;🌟&lt;/span&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Did this answer help you?&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;If so, please consider:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Adding karma to show it was useful&lt;/LI&gt;&lt;LI&gt;Marking it as the solution if it resolved your issue&lt;/LI&gt;&lt;LI&gt;Commenting if you need any clarification&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Your feedback encourages the volunteers in this community to continue contributing&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 07:06:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745826#M241553</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-05-09T07:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Value from and Event</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745867#M241561</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/170906"&gt;@livehybrid&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt; and&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;! This is my first real post here, so I appreciate you bearing with me as I may not have provided a complete picture.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;'s answer provided a clear example of how I can use mvfind and mvindex to extract the correct data. The only thing I had to add was a \b word boundary to the mvfind regex, so it wouldn't hit the earlier partial match. Here is the query:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=okta "debugContext.debugData.privilegeGranted"="*"
| eval type_index = mvfind('target{}.type', "CUSTOM_ROLE\b")
| eval "Target Name" = mvindex('target{}.displayName', type_index)
| eval "Target ID" = mvindex('target{}.alternateId', type_index)
| rename actor.displayName as "Actor", description as "Action",
  debugContext.debugData.privilegeGranted as "Role(s)"
| table Time, Actor, Action, "Target Name", "Target ID", Action, "Role(s)"&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 09 May 2025 18:47:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-Value-from-and-Event/m-p/745867#M241561</guid>
      <dc:creator>bill</dc:creator>
      <dc:date>2025-05-09T18:47:06Z</dc:date>
    </item>
  </channel>
</rss>

