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
lachlanP
Helper II
Helper II

Parsing a JSON field dynamically, based on another column

I have a data set where one column, "uuid", is a unique id of the row, and another column is a JSON packet. The JSON packet is structured as follows:

 

{

       "12345": {

              "key1": "value1",

              "key2": "value2",

              "importantKey": true

       },

       "678910": {

              "key1": "value1",

              "key2": "value2",

              "importantKey": false

       }

}

 

Where one of the first keys, ex. "12345" is the uuid of the row. Only one of the elements matches the row and I dont care about the rest. 

 

What I need to do is extract the value of importantKey into a new column. Is there a way to parse a JSON column using M where I reference a json element dynamically, based on the uuid column? For instance, I tried parsing the column to JSON using JSON.Document([json text column]), then from that I tried to expand the record dynamically with:

 

= Table.ExpandRecordColumn(#"Inserted Parsed JSON", "JSON", {[uuid]}, {"New Column"})

 

hoping that [uuid] would reference the uuid column. It didnt, I received this error:

 

Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?

 

 

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

Hi @lachlanP,

Have a look at the following example:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjFV0lGqjsmLyVOAgBiIaIySlQKyMFw2O7XSECQZo1SWmFOaCmTr4FBmhKTMCIeyzNyC/KKSxLwS79RKkPKSotJUJHW1OiguMzO3sDQ0GCCnpSXmFKO4DcSuVYrViYa6azQgKQvIWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [uuid = _t, JSON = _t]),
    #"Added Parsed JSON" = Table.AddColumn(Source, "Parsed JSON", each Json.Document([JSON])),
    #"Added Relevant JSON" = Table.AddColumn(#"Added Parsed JSON", "Relevant JSON", each Record.Field([Parsed JSON],[uuid])),
    #"Added importantKey" = Table.AddColumn(#"Added Relevant JSON", "importantKey", each Record.Field([Relevant JSON],"importantKey"), type logical)
in
    #"Added importantKey"

 

SpartaBI_1-1655028451536.png



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

2 REPLIES 2
SpartaBI
Community Champion
Community Champion

Hi @lachlanP,

Have a look at the following example:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjFV0lGqjsmLyVOAgBiIaIySlQKyMFw2O7XSECQZo1SWmFOaCmTr4FBmhKTMCIeyzNyC/KKSxLwS79RKkPKSotJUJHW1OiguMzO3sDQ0GCCnpSXmFKO4DcSuVYrViYa6azQgKQvIWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [uuid = _t, JSON = _t]),
    #"Added Parsed JSON" = Table.AddColumn(Source, "Parsed JSON", each Json.Document([JSON])),
    #"Added Relevant JSON" = Table.AddColumn(#"Added Parsed JSON", "Relevant JSON", each Record.Field([Parsed JSON],[uuid])),
    #"Added importantKey" = Table.AddColumn(#"Added Relevant JSON", "importantKey", each Record.Field([Relevant JSON],"importantKey"), type logical)
in
    #"Added importantKey"

 

SpartaBI_1-1655028451536.png



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

lachlanP
Helper II
Helper II

Maybe a clearer way to ask the question is:
Is there a way to select a component of a JSON object in Power Query?

 

In Javascript, for example, I would parse the json object and then I could select the element I want with:

 

jsonObject[uuid]

 

Is there something similar in power query? Like:

Json.Document([jsonTextColumn])[uuid]

where "uuid" is another column in the table.

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.