0

I'm trying to import a JSON file containing multiple unrelated 1D arrays with variable amount of elements into Excel.

The JSON I wrote:

{
    "table":[1,2,3],
    "table2":["A","B","C"],
    "table3":["a","b","c"]
    }

When I import the file using Power Query and expand the columns, it multiplies the previous entries each time I expand a new column.
enter image description here

Is there a way to show the elements of each array below each other and each array as a new column?

1 Answer 1

1

One method would be to transform each Record into a List and then create a table using Table.FromColumns method.

This needs to be done from the Advanced Editor:

Read the code comments and explore the Applied Steps to better understand. Also HELP topics for the various functions will be useful

let

//Change following line to reflect your actual data source
    Source = Json.Document(File.Contents("C:\Users\ron\Desktop\New Text Document.txt")),

//Get Field Names (= table names)
    fieldNames = Record.FieldNames(Source),

//Create a list of lists whereby each sublist is derived from the original record
    jsonLists = List.Accumulate(fieldNames,{}, (state, current)=> state & {Record.Field(Source,current)}),

//Convert the lists into columns of a new table
    myTable = Table.FromColumns(
        jsonLists,
        fieldNames
    )
in
    myTable

Results
enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! That solved my issue completely

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.