cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
bboysen
Regular Visitor

JSON Keys Change for each record

Hello,

 

I have a JSON file that I am pulling via API; I am running into an issue when trying to expand the record into individual columns to access the values. Below is a snip of the JSON object.  I am trying to access the start and stop within the time_bucket, but the next JSON key changes each time that value gets updated. Any insight on how to dynamically access the data would be greatly appreciated.

 

"-NNNhF0luJcfv-QqKwux": {
            "sections": {
                "midpoint_section": {
                          "time_bucket": {
                            "-NNgtF6n9q3qeaE_ArL6": {
                                "start"1675790384409,
                                "stop"1675790451218,
                                "uid""CcjuXG7To7XXP0C0R696v7n1zHk2"
                              }
                        }
                    }
        },
 "-NNNhFuUfWs6cL9u3Y_S": {    
            "sections": {
                "midpoint_section": {
                        "time_bucket": {
                            "-NNgtyoJmdB5xbNb92fX": {
                                "start"1675790606877,
                                "stop"1675790642483,
                                "uid""CcjuXG7To7XXP0C0R696v7n1zHk2"
                            }
                        }
                    }
        }
1 ACCEPTED SOLUTION
jbwtp
Memorable Member
Memorable Member

Hi @bboysen,

 

the code which I posted works with a record and I think that you are trying to apply it to a table (according to what I see).

 

try using AddColumn [from the point on your screenshot, i.e. the time_stamp column does exist, but not yet expanded] to add this code:

Record.Field([time_bucket], Record.FieldNames([time_bucket]){0})

This will/should estract the record with start/stop regardless of the actual "tag" of the record.

 

Cheers,

John  

I think 

View solution in original post

4 REPLIES 4
jbwtp
Memorable Member
Memorable Member

Hi @bboysen,

 

This is a generalised approach, let me know if you'll have difficulties adopting it for your scenario:

let
    Source = "{""-NNNhF0luJcfv-QqKwux"": {#(cr)#(lf)            ""sections"": {#(cr)#(lf)                ""midpoint_section"": {#(cr)#(lf)                          ""time_bucket"": {#(cr)#(lf)                            ""-NNgtF6n9q3qeaE_ArL6"": {#(cr)#(lf)                                ""start"": 1675790384409,#(cr)#(lf)                                ""stop"": 1675790451218,#(cr)#(lf)                                ""uid"": ""CcjuXG7To7XXP0C0R696v7n1zHk2""#(cr)#(lf)                              }#(cr)#(lf)                        }#(cr)#(lf)                    }#(cr)#(lf)        }#(cr)#(lf)}#(cr)#(lf)}",
    json = Json.Document(Source),
    record = List.Last(List.Generate(()=>json, each not List.Contains(Record.FieldNames(_), "start"), each Record.Field(_, Record.FieldNames(_){0}))),
    Custom1 = Record.Field(record, Record.FieldNames(record){0})
in
    Custom1

 

Kind regards,

John

John, thank you for the information this works great with the one recorded. When I apply this solution to my main data file it gets the following error message. 

 

bboysen_0-1676498399854.png

 

 

Little more detail and I should have included some of this before. When I click to expand time_bucket I get the following 

bboysen_1-1676498516219.png

When I click to load more, I get about 200 more records within the list. 

 

Each one creates a new column within the table. 

bboysen_2-1676498616763.png

 

I am trying to figure out how to get down to the next record without creating new columns for each of the parent records. 

 

jbwtp
Memorable Member
Memorable Member

Hi @bboysen,

 

the code which I posted works with a record and I think that you are trying to apply it to a table (according to what I see).

 

try using AddColumn [from the point on your screenshot, i.e. the time_stamp column does exist, but not yet expanded] to add this code:

Record.Field([time_bucket], Record.FieldNames([time_bucket]){0})

This will/should estract the record with start/stop regardless of the actual "tag" of the record.

 

Cheers,

John  

I think 

John, this is money. Thank you, sir; the sad part is that I was missing one little item. 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors