<?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 do you extract key/value pairs when the data is verbose and sometimes inconsistent? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433796#M123841</link>
    <description>&lt;P&gt;Hi @joemiller,&lt;BR /&gt;
Glad to help you. It seems you did some workarounds with my solutions to get a better result. That's a great thing to learning and improving our knowledge. Keep it up.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Happy Splunking&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Oct 2018 08:08:04 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2018-10-16T08:08:04Z</dc:date>
    <item>
      <title>How do you extract key/value pairs when the data is verbose and sometimes inconsistent?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433790#M123835</link>
      <description>&lt;P&gt;I'm having trouble extracting key/value pairs from a set of data. I think there are two separate problems that are making this difficult.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt; The key/value data has redundant descriptors. For example rather than &lt;CODE&gt;{"foo":"bar"}&lt;/CODE&gt;, the data looks like &lt;CODE&gt;{"Name":"foo","Value":"bar"}&lt;/CODE&gt;.&lt;/LI&gt;
&lt;LI&gt;The data is sometimes coming in with the value before the key, e.g. &lt;CODE&gt;{"Value":"bar","Name":"foo"}&lt;/CODE&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Each event also has several of these pairs (I'll include some examples below). I'm looking for a way to consistently extract from this data such that I get a new field (e.g. &lt;CODE&gt;foo&lt;/CODE&gt;) with the corresponding value (e.g. &lt;CODE&gt;bar&lt;/CODE&gt;) for each key/value pair in each event.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;_raw&lt;/CODE&gt; examples (data has been anonymized, but I haven't changed the structure):&lt;/P&gt;

&lt;P&gt;Key/Value:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"OrganizationName": "example.com", "Parameters": [{"Name": "Identity", "Value": "user@example.com"}, {"Name": "AccessRights", "Value": "ReadPermission"}, {"Name": "User", "Value": "Example-Username"}], "OrganizationId": "012-345-6789", "Operation": "Get-Something", "SessionId": "", "Workload": "Exchange", "CreationTime": "2018-10-12T22:08:13", "UserKey": "000011122233334445555", "ExternalAccess": false, "Version": 1, "Id": "00000000-0000-0000-0000-0000000000", "ObjectId": "targetusername", "ClientIP": "192.168.0.1:12345", "UserId": "admin@example.com", "RecordType": 1, "ResultStatus": "True", "UserType": 2, "OriginatingServer": "ABCD00000 (00.00.0000.000)"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Value/Key:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"OrganizationName": "example.com", "Parameters": [{"Value": "user@example.com", "Name": "Identity"}, {"Value": "Example-Username", "Name": "User"}, {"Value": "FullAccess", "Name": "AccessRights"}, {"Value": "All", "Name": "InheritanceType"}], "OrganizationId": "012-345-6789", "Operation": "Get-Something", "SessionId": "", "Workload": "Exchange", "CreationTime": "2018-10-12T22:08:13", "UserKey": "000011122233334445555", "ExternalAccess": false, "Version": 1, "Id": "00000000-0000-0000-0000-0000000000", "ObjectId": "targetusername", "ClientIP": "192.168.0.1:12345", "UserId": "admin@example.com", "RecordType": 1, "ResultStatus": "True", "UserType": 2, "OriginatingServer": "ABCD00000 (00.00.0000.000)"} 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I consistently extract all of the key/value pairs within &lt;CODE&gt;"Parameters": []&lt;/CODE&gt; ?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 23:51:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433790#M123835</guid>
      <dc:creator>joemiller</dc:creator>
      <dc:date>2018-10-12T23:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract key/value pairs when the data is verbose and sometimes inconsistent?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433791#M123836</link>
      <description>&lt;P&gt;Hi @joemiller,&lt;/P&gt;

&lt;P&gt;Can you please try the following search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH
| rename Parameters{}.* as * 
| eval temp=mvzip(Name,Value) 
| stats values(*) as * by _time Id temp 
| eval Name=mvindex(split(temp,","),0),Value=mvindex(split(temp,","),1) 
| eval {Name}=Value 
| stats values(*) as * by _time,Id 
| fields - temp Name Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Sample Search:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"OrganizationName\": \"example.com\", \"Parameters\": [{\"Name\": \"Identity\", \"Value\": \"user@example.com\"}, {\"Name\": \"AccessRights\", \"Value\": \"ReadPermission\"}, {\"Name\": \"User\", \"Value\": \"Example-Username\"}], \"OrganizationId\": \"012-345-6789\", \"Operation\": \"Get-Something\", \"SessionId\": \"\", \"Workload\": \"Exchange\", \"CreationTime\": \"2018-10-12T22:08:13\", \"UserKey\": \"000011122233334445555\", \"ExternalAccess\": false, \"Version\": 1, \"Id\": \"00000000-0000-0000-0000-0000000000\", \"ObjectId\": \"targetusername\", \"ClientIP\": \"192.168.0.1:12345\", \"UserId\": \"admin@example.com\", \"RecordType\": 1, \"ResultStatus\": \"True\", \"UserType\": 2, \"OriginatingServer\": \"ABCD00000 (00.00.0000.000)\"}" 
| append 
    [| makeresults 
    | eval _raw="{\"OrganizationName\": \"example.com\", \"Parameters\": [{\"Value\": \"user@example.com\", \"Name\": \"Identity\"}, {\"Value\": \"Example-Username\", \"Name\": \"User\"}, {\"Value\": \"FullAccess\", \"Name\": \"AccessRights\"}, {\"Value\": \"All\", \"Name\": \"InheritanceType\"}], \"OrganizationId\": \"012-345-6789\", \"Operation\": \"Get-Something\", \"SessionId\": \"\", \"Workload\": \"Exchange\", \"CreationTime\": \"2018-10-12T22:08:13\", \"UserKey\": \"000011122233334445555\", \"ExternalAccess\": false, \"Version\": 1, \"Id\": \"00000000-0000-0000-0000-0000000001\", \"ObjectId\": \"targetusername\", \"ClientIP\": \"192.168.0.1:12345\", \"UserId\": \"admin@example.com\", \"RecordType\": 1, \"ResultStatus\": \"True\", \"UserType\": 2, \"OriginatingServer\": \"ABCD00000 (00.00.0000.000)\"} "] 
| kv 
| rename Parameters{}.* as * 
| eval temp=mvzip(Name,Value) 
| stats values(*) as * by _time Id temp 
| eval Name=mvindex(split(temp,","),0),Value=mvindex(split(temp,","),1) 
| eval {Name}=Value 
| stats values(*) as * by _time,Id 
| fields - temp Name Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 13 Oct 2018 06:43:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433791#M123836</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-10-13T06:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract key/value pairs when the data is verbose and sometimes inconsistent?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433792#M123837</link>
      <description>&lt;P&gt;This is great! Thank you very much! It works for both of the examples I gave in my original post, so I will mark it as the answer.&lt;/P&gt;

&lt;P&gt;I just got another event where one of the parameters has a blank value, and in that case, this doesn't quite work. I'm going to play around with it a bit and see if I can make it work for that case too. If you have any suggestions, I would also appreciate that very much! Here's that example, in the makeresults format you used (I just used one of the existing ones and replaced the "Parameters[]" value, and incremented the "Id" value):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| makeresults | eval _raw="{\"OrganizationName\": \"example.com\", \"Parameters\": [{\"Value\": \"\", \"Name\": \"DomainController\"}, {\"Value\": \"example.com/Microsoft Exchange Hosted Organizations/example.com/DiscoverySearchMailbox{000000-00000-00000-0000-00000}\", \"Name\": \"Identity\"}, {\"Value\": \"ABC000000.example.com/Microsoft Exchange Hosted Organizations/example.com/Discovery Management\", \"Name\": \"User\"}, {\"Value\": \"FullAccess\", \"Name\": \"AccessRights\"}], \"OrganizationId\": \"012-345-6789\", \"Operation\": \"Get-Something\", \"SessionId\": \"\", \"Workload\": \"Exchange\", \"CreationTime\": \"2018-10-12T22:08:13\", \"UserKey\": \"000011122233334445555\", \"ExternalAccess\": false, \"Version\": 1, \"Id\": \"00000000-0000-0000-0000-0000000003\", \"ObjectId\": \"targetusername\", \"ClientIP\": \"192.168.0.1:12345\", \"UserId\": \"admin@example.com\", \"RecordType\": 1, \"ResultStatus\": \"True\", \"UserType\": 2, \"OriginatingServer\": \"ABCD00000 (00.00.0000.000)\"} "]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The thing that is different in this event is that the &lt;CODE&gt;"Name":"DomainController"&lt;/CODE&gt; has a &lt;CODE&gt;"Value":""&lt;/CODE&gt; (blank). This causes your search to produce AccessRights="" (blank) and User="FullAccess" (which , should be the value of AccessRights).&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 17:17:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433792#M123837</guid>
      <dc:creator>joemiller</dc:creator>
      <dc:date>2018-10-15T17:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract key/value pairs when the data is verbose and sometimes inconsistent?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433793#M123838</link>
      <description>&lt;P&gt;Okay, I ended up adding this line:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex mode=sed "s/Value\": \"\"/Value\": \"empty\"/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;right before all the other commands you suggested, and that fixed the problem related to empty values of "Value". But please let me know if you suggest something different. Thanks again for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 20:57:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433793#M123838</guid>
      <dc:creator>joemiller</dc:creator>
      <dc:date>2018-10-15T20:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract key/value pairs when the data is verbose and sometimes inconsistent?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433794#M123839</link>
      <description>&lt;P&gt;Okay actually, I still have a small problem.. when I do this on the test search using makeresults, I have to do the rex and then do &lt;CODE&gt;| kv&lt;/CODE&gt; to get the Parameters field to use the modified version of _raw. But if I do that rex on a "live" search and then do &lt;CODE&gt;| kv&lt;/CODE&gt;, I get duplicates of every field..&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 21:54:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433794#M123839</guid>
      <dc:creator>joemiller</dc:creator>
      <dc:date>2018-10-15T21:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract key/value pairs when the data is verbose and sometimes inconsistent?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433795#M123840</link>
      <description>&lt;P&gt;And I think I fixed that last issue by adding a &lt;CODE&gt;| fields _raw&lt;/CODE&gt; before the &lt;CODE&gt;| kv&lt;/CODE&gt;..&lt;/P&gt;</description>
      <pubDate>Mon, 15 Oct 2018 22:31:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433795#M123840</guid>
      <dc:creator>joemiller</dc:creator>
      <dc:date>2018-10-15T22:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract key/value pairs when the data is verbose and sometimes inconsistent?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433796#M123841</link>
      <description>&lt;P&gt;Hi @joemiller,&lt;BR /&gt;
Glad to help you. It seems you did some workarounds with my solutions to get a better result. That's a great thing to learning and improving our knowledge. Keep it up.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Happy Splunking&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Oct 2018 08:08:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-key-value-pairs-when-the-data-is-verbose-and/m-p/433796#M123841</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-10-16T08:08:04Z</dc:date>
    </item>
  </channel>
</rss>

