<?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 parse nested JSON in Office 365 logging in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390873#M69909</link>
    <description>&lt;P&gt;@korstiaan &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | rename Parameters{}.* as * |  eval temp=mvzip(Name,Value) | mvexpand temp | eval Name=mvindex(split(temp,","),0), Value=mvindex(split(temp,","),1) | table Name Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have created a sample search on the bases of &lt;CODE&gt;Parameters&lt;/CODE&gt; JSON. It will help you to understand the search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval _raw="{\"Parameters\":[{\"Name\":\"SentTo\",\"Value\":\"this is a test\"},{\"Name\":\"ModerateMessageByUser\",\"Value\":\"John Doe\"},{\"Name\":\"Name\",\"Value\":\"Forward_Mails\"},{\"Name\":\"StopRuleProcessing\",\"Value\":\"False\"},{\"Name\":\"Mode\",\"Value\":\"Enforce\"},{\"Name\":\"Comments\",\"Value\":\"\"},{\"Name\":\"RuleErrorAction\",\"Value\":\"Ignore\"},{\"Name\":\"SenderAddressLocation\",\"Value\":\"Header\"}]}" | kv | rename Parameters{}.* as * |  eval temp=mvzip(Name,Value) | mvexpand temp | eval Name=mvindex(split(temp,","),0), Value=mvindex(split(temp,","),1) | table Name Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;UPDATED&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | rename Parameters{}.* as * |  eval temp=mvzip(Name,Value) | mvexpand temp | eval Name=mvindex(split(temp,","),0), Value=mvindex(split(temp,","),1) | eval {Name}=Value | stats values(*) as * by _time Id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sample:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"Id\":\"4f438b66-64b2-4291-0dec-08d682ccad1c\", \"Parameters\":[{\"Name\":\"SentTo\",\"Value\":\"this is a test\"},{\"Name\":\"ModerateMessageByUser\",\"Value\":\"John Doe\"},{\"Name\":\"Name\",\"Value\":\"Forward_Mails\"},{\"Name\":\"StopRuleProcessing\",\"Value\":\"False\"},{\"Name\":\"Mode\",\"Value\":\"Enforce\"},{\"Name\":\"Comments\",\"Value\":\"\"},{\"Name\":\"RuleErrorAction\",\"Value\":\"Ignore\"},{\"Name\":\"SenderAddressLocation\",\"Value\":\"Header\"}]}" 
| kv 
| rename Parameters{}.* as * 
| eval temp=mvzip(Name,Value) 
| mvexpand temp 
| eval Name=mvindex(split(temp,","),0), Value=mvindex(split(temp,","),1) 
| eval {Name}=Value
| stats values(*) as * by _time Id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 04 Apr 2019 10:58:27 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2019-04-04T10:58:27Z</dc:date>
    <item>
      <title>How to parse nested JSON in Office 365 logging</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390872#M69908</link>
      <description>&lt;P&gt;Hi All, I hope someone is able to help me resolve an issue that I have with some nested fields in JSON. I'd like to get the data out of the 'Parameters' field.  &lt;/P&gt;

&lt;P&gt;The data is in CSV format and the JSON is in the field AuditData. I use the spath command to get most of the fields with the following search:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=auditlog |spath input=AuditData&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Most of the fields get extracted, however there is nested json in the 'Parameters' field. An when I use the spath command it will create two new fields: &lt;/P&gt;

&lt;P&gt;Parameters{}.Name&lt;BR /&gt;
Parameters{}.Value&lt;/P&gt;

&lt;P&gt;Parameters{}.Name contains, 'SentTo', 'ModerateMessageByUser' etc. &lt;BR /&gt;
Parameters{}.Value contains the values belonging to the above names.&lt;/P&gt;

&lt;P&gt;However what I'd like to get is a field with the Parameter Name and the accompanying Parameter Value  e.g:&lt;BR /&gt;
&lt;STRONG&gt;SentTo&lt;/STRONG&gt;(Fieldname) this is a test (Value)&lt;BR /&gt;
&lt;STRONG&gt;ModerateMessageByUser&lt;/STRONG&gt;(Fieldname)John Doe (Value)&lt;/P&gt;

&lt;P&gt;Hopefully this makes sense i've added an example event below:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;"outlook.office365.com","7c06ff67-4425-4eb6-9df5-a7e9b0a07fa0","False","ExchangeAdmin","1/25/2019 1:54:50 PM","test@test.onmicrosoft.com","New-TransportRule","{""CreationTime"":""2019-01-25T13:54:50"",""Id"":""4f438b66-64b2-4291-0dec-08d682ccad1c"",""Operation"":""New-TransportRule"",""OrganizationId"":""f2b20553-47ca-41c0-9766-fba93daf6cf1"",""RecordType"":1,""ResultStatus"":""True"",""UserKey"":""1003200036269B2E"",""UserType"":2,""Version"":1,""Workload"":""Exchange"",""ClientIP"":""1.1.1:42796"",""ObjectId"":"""",""UserId"":""test@test.onmicrosoft.com"",""ExternalAccess"":false,""OrganizationName"":""test.onmicrosoft.com"",""OriginatingServer"":""AM6PR04MB6088 (15.20.1558.000)"",""Parameters"":[{""Name"":""SentTo"",""Value"":""this is a test""},{""Name"":""ModerateMessageByUser"",""Value"":""John Doe""},{""Name"":""Name"",""Value"":""Forward_Mails""},{""Name"":""StopRuleProcessing"",""Value"":""False""},{""Name"":""Mode"",""Value"":""Enforce""},{""Name"":""Comments"",""Value"":""""},{""Name"":""RuleErrorAction"",""Value"":""Ignore""},{""Name"":""SenderAddressLocation"",""Value"":""Header""}],""SessionId"":""8240fe03-0507-4794-99c3-e601796be84b""}","77","123","4f438b66-64b2-4291-0dec-08d682ccad1c","True","Unchanged"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 10:41:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390872#M69908</guid>
      <dc:creator>korstiaan</dc:creator>
      <dc:date>2019-04-04T10:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse nested JSON in Office 365 logging</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390873#M69909</link>
      <description>&lt;P&gt;@korstiaan &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | rename Parameters{}.* as * |  eval temp=mvzip(Name,Value) | mvexpand temp | eval Name=mvindex(split(temp,","),0), Value=mvindex(split(temp,","),1) | table Name Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have created a sample search on the bases of &lt;CODE&gt;Parameters&lt;/CODE&gt; JSON. It will help you to understand the search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval _raw="{\"Parameters\":[{\"Name\":\"SentTo\",\"Value\":\"this is a test\"},{\"Name\":\"ModerateMessageByUser\",\"Value\":\"John Doe\"},{\"Name\":\"Name\",\"Value\":\"Forward_Mails\"},{\"Name\":\"StopRuleProcessing\",\"Value\":\"False\"},{\"Name\":\"Mode\",\"Value\":\"Enforce\"},{\"Name\":\"Comments\",\"Value\":\"\"},{\"Name\":\"RuleErrorAction\",\"Value\":\"Ignore\"},{\"Name\":\"SenderAddressLocation\",\"Value\":\"Header\"}]}" | kv | rename Parameters{}.* as * |  eval temp=mvzip(Name,Value) | mvexpand temp | eval Name=mvindex(split(temp,","),0), Value=mvindex(split(temp,","),1) | table Name Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;UPDATED&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR_SEARCH | rename Parameters{}.* as * |  eval temp=mvzip(Name,Value) | mvexpand temp | eval Name=mvindex(split(temp,","),0), Value=mvindex(split(temp,","),1) | eval {Name}=Value | stats values(*) as * by _time Id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sample:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"Id\":\"4f438b66-64b2-4291-0dec-08d682ccad1c\", \"Parameters\":[{\"Name\":\"SentTo\",\"Value\":\"this is a test\"},{\"Name\":\"ModerateMessageByUser\",\"Value\":\"John Doe\"},{\"Name\":\"Name\",\"Value\":\"Forward_Mails\"},{\"Name\":\"StopRuleProcessing\",\"Value\":\"False\"},{\"Name\":\"Mode\",\"Value\":\"Enforce\"},{\"Name\":\"Comments\",\"Value\":\"\"},{\"Name\":\"RuleErrorAction\",\"Value\":\"Ignore\"},{\"Name\":\"SenderAddressLocation\",\"Value\":\"Header\"}]}" 
| kv 
| rename Parameters{}.* as * 
| eval temp=mvzip(Name,Value) 
| mvexpand temp 
| eval Name=mvindex(split(temp,","),0), Value=mvindex(split(temp,","),1) 
| eval {Name}=Value
| stats values(*) as * by _time Id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 10:58:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390873#M69909</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-04T10:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse nested JSON in Office 365 logging</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390874#M69910</link>
      <description>&lt;P&gt;Hi, this is almost what I want thank you. So now you have a field called Name and Value with the correct information. However I'd like that the Paramater.{}Name will be the field name and the Value will be the value of that specific field e.g.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;SentTo&lt;/STRONG&gt; is a field and it contains the value 'this is a test'&lt;BR /&gt;
&lt;STRONG&gt;ModerateMessageByUser&lt;/STRONG&gt; is a field and it contains the value 'John Doe' &lt;/P&gt;

&lt;P&gt;Does that make sense? &lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 11:52:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390874#M69910</guid>
      <dc:creator>korstiaan</dc:creator>
      <dc:date>2019-04-08T11:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse nested JSON in Office 365 logging</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390875#M69911</link>
      <description>&lt;P&gt;@korstiaan&lt;/P&gt;

&lt;P&gt;Please check the updated answer.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 12:11:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390875#M69911</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-08T12:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse nested JSON in Office 365 logging</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390876#M69912</link>
      <description>&lt;P&gt;Thanks that will work! Can you explain to me how the mvzip and mvexpand work for the above search.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 12:25:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390876#M69912</guid>
      <dc:creator>korstiaan</dc:creator>
      <dc:date>2019-04-08T12:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse nested JSON in Office 365 logging</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390877#M69913</link>
      <description>&lt;P&gt;@korstiaan&lt;/P&gt;

&lt;P&gt;Here, your single event has below multivalued fields, &lt;CODE&gt;Parameters{}.Name&lt;/CODE&gt; and &lt;CODE&gt;Parameters{}.Value&lt;/CODE&gt;. If we want to get the related value of each value, means the first set of value from &lt;CODE&gt;Parameters{}.&lt;/CODE&gt; JSON, then we use &lt;CODE&gt;mvzip&lt;/CODE&gt; by passing the required fields. In our case, &lt;CODE&gt;Parameters{}.Name&lt;/CODE&gt; and &lt;CODE&gt;Parameters{}.Value&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;mvzip&lt;/CODE&gt;: This function takes two multivalue fields, X and Y, and combines them by stitching together the first value of X with the first value of field Y, then the second with the second, and so on.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/MultivalueEvalFunctions#mvzip.28X.2CY.2C.22Z.22.29"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.5/SearchReference/MultivalueEvalFunctions#mvzip.28X.2CY.2C.22Z.22.29&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;After doing mvzip, now we have multi-valued filed &lt;CODE&gt;temp&lt;/CODE&gt;. Here we are using &lt;CODE&gt;mvexpand&lt;/CODE&gt; to separate them.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;mvexpand&lt;/CODE&gt;: Expands the values of a multivalue field into separate events, one event for each value in the multivalue field.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/mvexpand"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/mvexpand&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;After &lt;CODE&gt;mvexpand&lt;/CODE&gt;, your single event expanding with multiple events. &lt;/P&gt;

&lt;P&gt;Here, I've used dynamic eval by using &lt;CODE&gt;{}&lt;/CODE&gt;.  &lt;CODE&gt;| eval {Name}=Value&lt;/CODE&gt; is dynamic eval which is creating a field with the name which is available in &lt;CODE&gt;Name&lt;/CODE&gt; filed as a value. In this case, &lt;CODE&gt;SentTo&lt;/CODE&gt; will be created.&lt;/P&gt;

&lt;P&gt;I suggest you execute my sample search step by step and you will get how it is working.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Happy Splunking&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 12:50:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390877#M69913</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-08T12:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse nested JSON in Office 365 logging</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390878#M69914</link>
      <description>&lt;P&gt;Thank you Kamlesh, very helpful. &lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 13:11:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390878#M69914</guid>
      <dc:creator>korstiaan</dc:creator>
      <dc:date>2019-04-08T13:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse nested JSON in Office 365 logging</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390879#M69915</link>
      <description>&lt;P&gt;Hi @kamalesh,&lt;/P&gt;

&lt;P&gt;Thanks. As we discussed in the slack channel, I tried the search, but it creates additional events for each Name:VAlue pairs. can this be addressed please?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 13:56:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-nested-JSON-in-Office-365-logging/m-p/390879#M69915</guid>
      <dc:creator>cpaul8</dc:creator>
      <dc:date>2019-06-28T13:56:01Z</dc:date>
    </item>
  </channel>
</rss>

