Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Stanil
Regular Visitor

Multi-level JSON column

Hi,

 

I have output from some API. There is a column "Entities" I want to extract, originally it is in JSON format. I want to have duplicated the rows for each Key-value pair extracted from Entities. 

I "unrolled" one level by using Table.ExpandListColumn:

Stanil_0-1744152302408.png

 

but in the output I get different types of data in it: JSON records, JSON lists, or empty values. (Thanks, Microsoft, for not keeping up any standards in the LogAnalytics API).

Now, if I try to parse it again by Table.TransformColumns, I always stumble upon some errors.

I have some ideas, not sure which one are useful here: 

 a)  to convert the "record" type back to text and stop modeling the data

 b) to convert the "record" type into a list with one element (so add '[' and ']' at the beginning and the end of the record) and then unroll the list again

 c) to remove all brackets, and split the data by ',' to Key-Value Pair

 d) to convert the lists selectively into 2nd level records, without touching the 1st level records

 

I watched a few YT videos about converting JSON, but all of them (so far) assumed the JSON structure is flat and uniform for all the records. It's not the case here. Please point me in the right direction.

1 ACCEPTED SOLUTION
v-kathullac
Community Support
Community Support

Hi @Stanil,

 

Thank you for reaching out to the Microsoft Fabric Community Forum.


I have taken a sample JSON file, loaded it into Power BI, and applied a few steps to split the columns.

Please find the screenshot and Power Query steps attached for your reference

vkathullac_0-1744195690708.png

Power Query:

let

    Source = Table.FromRows({

        {1, "[{""Key1"": ""Value1""}, {""Key2"": ""Value2""}]"},

        {2, "{""Key3"": ""Value3""}"},

        {3, null},

        {4, "[{""Key4"": ""Value4"", ""Key5"": ""Value5""}]"},

        {5, "{""Key6"": ""Value6"", ""Key7"": ""Value7""}"}

    }, {"ID", "Entities"}),

    Parsed = Table.AddColumn(Source, "ParsedEntities", each try Json.Document([Entities]) otherwise null),

    NormalizedList = Table.AddColumn(Parsed, "EntityList", each

        if [ParsedEntities] = null then {}

        else if Value.Is([ParsedEntities], type list) then [ParsedEntities]

        else if Value.Is([ParsedEntities], type record) then {[ParsedEntities]}

        else {}, type list

    ),

    ExpandedList = Table.ExpandListColumn(NormalizedList, "EntityList"),

    AddKV = Table.AddColumn(ExpandedList, "KV", each

        if Value.Is([EntityList], type record) then Record.ToTable([EntityList]) else null

    ),

    ExpandedKV = Table.ExpandTableColumn(AddKV, "KV", {"Name", "Value"}),

    Final = Table.SelectColumns(ExpandedKV, {"ID", "Name", "Value"})

in

    Final

 

Output:

vkathullac_1-1744195916079.png

 

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya.

View solution in original post

2 REPLIES 2
v-kathullac
Community Support
Community Support

Hi @Stanil,

 

Thank you for reaching out to the Microsoft Fabric Community Forum.


I have taken a sample JSON file, loaded it into Power BI, and applied a few steps to split the columns.

Please find the screenshot and Power Query steps attached for your reference

vkathullac_0-1744195690708.png

Power Query:

let

    Source = Table.FromRows({

        {1, "[{""Key1"": ""Value1""}, {""Key2"": ""Value2""}]"},

        {2, "{""Key3"": ""Value3""}"},

        {3, null},

        {4, "[{""Key4"": ""Value4"", ""Key5"": ""Value5""}]"},

        {5, "{""Key6"": ""Value6"", ""Key7"": ""Value7""}"}

    }, {"ID", "Entities"}),

    Parsed = Table.AddColumn(Source, "ParsedEntities", each try Json.Document([Entities]) otherwise null),

    NormalizedList = Table.AddColumn(Parsed, "EntityList", each

        if [ParsedEntities] = null then {}

        else if Value.Is([ParsedEntities], type list) then [ParsedEntities]

        else if Value.Is([ParsedEntities], type record) then {[ParsedEntities]}

        else {}, type list

    ),

    ExpandedList = Table.ExpandListColumn(NormalizedList, "EntityList"),

    AddKV = Table.AddColumn(ExpandedList, "KV", each

        if Value.Is([EntityList], type record) then Record.ToTable([EntityList]) else null

    ),

    ExpandedKV = Table.ExpandTableColumn(AddKV, "KV", {"Name", "Value"}),

    Final = Table.SelectColumns(ExpandedKV, {"ID", "Name", "Value"})

in

    Final

 

Output:

vkathullac_1-1744195916079.png

 

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya.

lbendlin
Super User
Super User

Read about Value.Is - then probe the type of each value and handle its content accordingly.

 

Or - enumerate through all "Entities"  in your original JSON and parse these with try ... otherwise ...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.