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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply

Parsing JSON with differing children

Hi

I have a PowerQuery that consumes a json feed. This usally works really well. But, now I have added a new property to my json ("openForSale") that is a simple true/false and not an item like the others.

 

What I would like to output into my table is:

| campaign  | open for sale | name      |

| campaign1 | true          | triangles |

| campaign1 | true          | circles   |

| campaign1 | true          | squares   |

| campaign2 |               | lines     |

 

How my json looks

{

  "campaign1" : {

    "item1" : {"name" : "triangles", ...},

    "item2" : {"name" : "circles", ...},

    "item3" : {"name" : "squares", ...},

    "openForSale" : true 

  },

  "campaign2": {

    "item17" : {"name" : "lines", ...}

  }

}

 

How my PowerQuery, that used to work looks (start of it)

let json = Json.Document(Web.Contents("https://thewebsite.com/the.json")),
level0 = Record.ToTable(json),

campaignLevel = Table.AddColumn(level0, "campaignLevel", each Record.ToTable([Value])),
campaignLevelExp = Table.ExpandTableColumn(campaignLevel, "campaignLevel", {"Name", "Value"}, {"CampaignName", "Campaign.Value"}),

itemLevel = Table.AddColumn(campaignLevelExp, "itemLevel", each Record.ToTable([Campaign.Value])),
itemLevel _exp = Table.ExpandTableColumn(itemLevel, "itemLevel", {"Name", "Value"}, {"Team", "itemLevel.Value"})

...

 

I believe the answer is in the line starting with "itemLevel =" where I should be able filter instead of iterating "each Record...".

 

Help is very much appreciated!

1 ACCEPTED SOLUTION

yay!

I got it working.

 

let json = Json.Document(Web.Contents("https://thewebsite.com/the.json")),
organizationLevel = Record.ToTable(Source),
campaignLevel = Table.AddColumn(organizationLevel , "Campaign", each Record.ToTable([Value])),
campaignLevelExp = Table.ExpandTableColumn(campaignLevel, "Campaign", {"Name", "Value"}, {"CampaignName", "Campaign.Value"}),
itemLevel = Table.ExpandRecordColumn(campaignLevelExp, "Campaign.Value", {"item1"}, {"item1"}),
itemLevelExp = Table.ExpandRecordColumn(itemLevel, "item1", {"openForSale", "items"}, {"openForSale", "items"}),

itemsToList = Table.TransformColumns(itemLevelExp,{{"items", Record.ToList}}),
itemsToListExp = Table.ExpandListColumn(itemsToList, "items"),

allItems = Table.ExpandRecordColumn(itemsToListExp, "items", {"name"}, {"name"})

View solution in original post

1 REPLY 1

yay!

I got it working.

 

let json = Json.Document(Web.Contents("https://thewebsite.com/the.json")),
organizationLevel = Record.ToTable(Source),
campaignLevel = Table.AddColumn(organizationLevel , "Campaign", each Record.ToTable([Value])),
campaignLevelExp = Table.ExpandTableColumn(campaignLevel, "Campaign", {"Name", "Value"}, {"CampaignName", "Campaign.Value"}),
itemLevel = Table.ExpandRecordColumn(campaignLevelExp, "Campaign.Value", {"item1"}, {"item1"}),
itemLevelExp = Table.ExpandRecordColumn(itemLevel, "item1", {"openForSale", "items"}, {"openForSale", "items"}),

itemsToList = Table.TransformColumns(itemLevelExp,{{"items", Record.ToList}}),
itemsToListExp = Table.ExpandListColumn(itemsToList, "items"),

allItems = Table.ExpandRecordColumn(itemsToListExp, "items", {"name"}, {"name"})

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.