Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Expand custom column nested in JSON record - API

I'm working with the QuickBooks API but this could apply to other nested custom columns in a json API call. Is there a function that will expand the CustomFields for me on 1 line for n number of cust...
  • ImkeF's avatar
    8 years ago

    Yes, a shorter way is this:

     

    let
        Source = Json.Document(File.Contents("C:\Users\Desktop\example_credit2.json")),
        #"Converted to Table" = Record.ToTable(Source),
        #"Expanded Value" = Table.ExpandRecordColumn(#"Converted to Table", "Value", {"RemainingCredit", "domain", "sparse", "Id", "SyncToken", "CustomField", "DocNumber", "TxnDate"}, {"RemainingCredit", "domain", "sparse", "Id", "SyncToken", "CustomField", "DocNumber", "TxnDate"}),
        ToTable = Table.AddColumn(#"Expanded Value", "Custom", each Table.PromoteHeaders(Table.Transpose(Table.SelectColumns(Table.FromRecords([CustomField]), {"Name", "Value"})))),
        #"Expanded Custom" = Table.ExpandTableColumn(ToTable, "Custom", Table.ColumnNames(ToTable[Custom]{0}))
    in
        #"Expanded Custom"

    It is also dynamic: If there will be more "columns" in the CustomField, they will be expanded automatically as well.