Forum Discussion
Chris Davies
Apr 29, 2018Copper Contributor
Parsing JSON to seperate columns
I am trying to convert JSON data that is provided by the Audit log for Office365 for creation of Teams into separate columns so I can use the data more effectively: The data looks like this: ...
SergeiBaklan
Apr 30, 2018Diamond Contributor
Not sure about macro, as variant you may do that with Power Query. For this particular sample generated script looks like (and attached)
let Source = Json.Document(File.Contents("C:\Test\sample.json")), ToTable = Record.ToTable(Source), TransposeTable = Table.Transpose(ToTable), PromotHeaders = Table.PromoteHeaders(TransposeTable, [PromoteAllScalars=true]), ChangeType = Table.TransformColumnTypes(PromotHeaders,{{"CreationTime", type datetime}, {"Id", type text}, {"Operation", type text}, {"OrganizationId", type text}, {"RecordType", Int64.Type}, {"UserKey", type text}, {"UserType", Int64.Type}, {"Version", Int64.Type}, {"Workload", type text}, {"ClientIP", type text}, {"ObjectId", type text}, {"UserId", type text}, {"CorrelationId", type text}, {"EventSource", type text}, {"ItemType", type text}, {"Site", type text}, {"UserAgent", type text}, {"ModifiedProperties", type any}}), ExpandModifiedProperties = Table.ExpandListColumn(ChangeType, "ModifiedProperties"), ExpandRecord = Table.ExpandRecordColumn(ExpandModifiedProperties, "ModifiedProperties", {"Name", "NewValue"}, {"Name", "NewValue"}) in ExpandRecord
for real data you shall expand lists for each field