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
AnandNamburi
Helper III
Helper III

How to retrieve data from recursive JOSN

Hi All,

 

I have  a JOSN file and the data in it is like below.

 

{

                "firstName": "Bidhan",

                "lastName": "Chatterjee",

                "age": 40,

                "address": {

                                "streetAddress": "144 J B Hazra Road",

                                "city": "Burdwan",

                                "state": "Paschimbanga",

                                "postalCode": "713102"

                },

                "phoneNumber": [{

                                                "type": "personal",

                                                "number": "09832209761"

                                },

                                {

                                                "type": "fax",

                                                "number": "91-342-2567692"

                                }

                ]

}

 

When I'm trying to retrive the data from the file I'm getting message likw below.

Capture.PNG

Can anyone help me out here, how to retrive the data from address and phone number coumns.

 

Thanks,

Anand

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi  @AnandNamburi 

you could try this way to retrieve data

let
    Source = Json.Document(File.Contents("C:\Users\Desktop\new.json")),
    #"Converted to Table" = Record.ToTable(Source),
    #"Pivoted Column" = Table.Pivot(#"Converted to Table", List.Distinct(#"Converted to Table"[Name]), "Name", "Value"),
    #"Expanded address" = Table.ExpandRecordColumn(#"Pivoted Column", "address", {"streetAddress", "city", "state", "postalCode"}, {"streetAddress", "city", "state", "postalCode"}),
    #"Expanded phoneNumber" = Table.ExpandListColumn(#"Expanded address", "phoneNumber"),
    #"Expanded phoneNumber1" = Table.ExpandRecordColumn(#"Expanded phoneNumber", "phoneNumber", {"type", "number"}, {"type", "number"})
in
    #"Expanded phoneNumber1"

Result:

4.JPG

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi  @AnandNamburi 

you could try this way to retrieve data

let
    Source = Json.Document(File.Contents("C:\Users\Desktop\new.json")),
    #"Converted to Table" = Record.ToTable(Source),
    #"Pivoted Column" = Table.Pivot(#"Converted to Table", List.Distinct(#"Converted to Table"[Name]), "Name", "Value"),
    #"Expanded address" = Table.ExpandRecordColumn(#"Pivoted Column", "address", {"streetAddress", "city", "state", "postalCode"}, {"streetAddress", "city", "state", "postalCode"}),
    #"Expanded phoneNumber" = Table.ExpandListColumn(#"Expanded address", "phoneNumber"),
    #"Expanded phoneNumber1" = Table.ExpandRecordColumn(#"Expanded phoneNumber", "phoneNumber", {"type", "number"}, {"type", "number"})
in
    #"Expanded phoneNumber1"

Result:

4.JPG

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lbendlin
Super User
Super User

This is not recursive, it's just a multi level hierarchy - that's what JSON is about.  

 

In Power Query you need to manually traverse that hierarchy and pick the fields that you want to convert into a flattened version. There's no magic "give me all the JSON data in a flat table" button, it's all manual work.

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.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

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
Top Kudoed Authors