Forum Discussion

ExcelPWRQ01's avatar
ExcelPWRQ01
New Member
2 years ago
Solved

Convert Partial JSON to Excel Columns?

Hello,   Problem Statement: We have this JSON file that comes from an external vendor that generates these files where we would like to convert MOST of the data fields to Excel columns and then le...
  • lbendlin's avatar
    lbendlin
    2 years ago
    let
        Source = Json.Document("
        [
        {
            ""field1"": ""blah 1"",
            ""field2"": ""blah 2"",
            ""rules"": [
                {
                    ""anotherfield1"": ""blah 3"",
                    ""anotherfield2"": ""blah 4"",
                    ""Pattern"": {
                        ""a"": ""blah 5"",
                        ""b"": ""blah 6""
                    }
                },
                {
                    ""anotherfield1"": ""blah 7"",
                    ""anotherfield2"": ""blah 8"",
                    ""Pattern"": {
                        ""a"": ""blah 9"",
                        ""b"": ""blah 10""
                    }
                }
            ]
        }
    ]
        
        "),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"field1", "field2", "rules"}, {"field1", "field2", "rules"}),
        #"Replaced Value" = Table.ReplaceValue(#"Expanded Column1",each [rules],each Text.FromBinary(Json.FromValue([rules])),Replacer.ReplaceValue,{"rules"})
    in
        #"Replaced Value"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.