[Office 365] Help parse json with key | value in data

Im working on log of O365 via O365 API.

I have sample log look like

"o365": {
"ExtendedProperties": [
        {
          "Name": "UserAgent",
          "Value": "Microsoft Office/15.0 (Windows NT 6.2; Microsoft Outlook 15.0.4420; Pro)"
        },
        {
          "Name": "UserAuthenticationMethod",
          "Value": "1"
        },
        {
          "Name": "RequestType",
          "Value": "OrgIdWsTrust2:process"
        },
        {
          "Name": "ResultStatusDetail",
          "Value": "Success"
        }
      ]
}

Now i want data become

{
  "o365": {
    "ExtendedProperties": {
      "UserAgent": "Microsoft Office/15.0 (Windows NT 6.2; Microsoft Outlook 15.0.4420; Pro)",
      "UserAuthenticationMethod": "1",
      "RequestType": "OrgIdWsTrust2:process",
      "ResultStatusDetail": "Success"
    }
  }
}

Someone tell me that should be use ruby filter, but i dont know how (i dont know ruby program).
Can someone help me finish parse log Office 365 ?
P/s: The number of elements in the array (ExtendedProperties) is unknown - maybe have 3 or 5 or 7 elements.

Thanks so much!

I tried this filter but not work

ruby {
      init => "
        def arrays_to_hash(h)
          h.each do |k,v|            
            value = v || k
            if value.is_a?(Array)
                value_hash = {}
                value.each_with_index do |v, i|
                    value_hash[i.to_s] = v
                end
                h[k] = value_hash
            end
            if value.is_a?(Hash) || value.is_a?(Array)
              arrays_to_hash(value)
            end
          end
        end
      "
      code => "arrays_to_hash([o365][ExtendedProperties])"
    }


Someone help me ?

The "arrays_to_hash([o365][ExtendedProperties])" line seems wrong. Try "arrays_to_hash(event.get('o365').get('ExtendedProperties')". I didn't check the rest of the code, though.

Thank @tudor but sth wrong in synstax ?

image

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.