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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Extract JSON data

Hi ,

I have a JSON string that i want to extract in power bi. It is the following JSON string:

 

 

 

{
  "id": "...",
  "name": "...",
  "address": "...",
  "types": [
    "shopping_mall",
    "point_of_interest",
    "establishment"
  ],
  "coordinates": {
    "lat": ...,
    "lng": ...
  },
  "rating": 3.7,
  "rating_n": 1495,
  "international_phone_number": "...",
  "current_popularity": 35,
  "populartimes": [
    {
      "name": "Monday",
      "data": [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        24,
        31,
        32,
        24,
        14,
        0,
        0,
        0,
        0,
        0,
        0
      ]
    },
  ],
  "time_spent": [
    15,
    60
  ]
}

 

 

 

The most important thing is the "populartimes": [...]. In this section I get the data of each day (times 7). And i want to extract this all in one column. I have come a whole end and got to this point (see picture 1)

power-bi-0.png

What i want is the following thing, but than for eacht column. 

power-bi-1.png

I have fold out this first column. But when I try to do this for the second column I get a lot more columns than the 24 I want to. What steps do I have to follow? Or is there a manuel that explains how to extract JSON data?

2 ACCEPTED SOLUTIONS
mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous ,

 

I think I have it, try the steps in this file.

PBIX

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


View solution in original post

Anonymous
Not applicable

HI @Anonymous,

I'm not so sure how your records stored, I copy your sample data and try to add more records, you can check below sample code if they suitable for your requirements.

Sample data:

Spoiler
{
   "id":"...",
   "name":"...",
   "address":"...",
   "types":[
      "shopping_mall",
      "point_of_interest",
      "establishment"
   ],
   "coordinates":{
      "lat":"...",
      "lng":"..."
   },
   "rating":3.7,
   "rating_n":1495,
   "international_phone_number":"...",
   "current_popularity":35,
   "populartimes":[
      {
         "name":"Monday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Tuesday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Wednesday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Thursday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Friday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Saturday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Sunday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      }
   ],
   "time_spent":[
      15,
      60
   ]
}​

Power query formula:

let
    Source = Json.Document(File.Contents("C:\Users\xxxxx\Desktop\sample.json"))[populartimes],
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"name", "data"}, {"name", "data"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Column1", "Merged", each Text.Combine(List.Transform([data],each Text.From(_)),",")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"data"}),
    #"Transposed Table" = Table.Transpose(#"Removed Columns"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Monday", type text}, {"Tuesday", type text}, {"Wednesday", type text}, {"Thursday", type text}, {"Friday", type text}, {"Saturday", type text}, {"Sunday", type text}})
in
    #"Changed Type"

16.png

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thank you both for your replys! 

Both answers are correct and does what i wanted. The difference is that one is solved with code and the other with power bi extractions.

Anonymous
Not applicable

HI @Anonymous,

I'm not so sure how your records stored, I copy your sample data and try to add more records, you can check below sample code if they suitable for your requirements.

Sample data:

Spoiler
{
   "id":"...",
   "name":"...",
   "address":"...",
   "types":[
      "shopping_mall",
      "point_of_interest",
      "establishment"
   ],
   "coordinates":{
      "lat":"...",
      "lng":"..."
   },
   "rating":3.7,
   "rating_n":1495,
   "international_phone_number":"...",
   "current_popularity":35,
   "populartimes":[
      {
         "name":"Monday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Tuesday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Wednesday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Thursday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Friday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Saturday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      },
      {
         "name":"Sunday",
         "data":[
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            24,
            31,
            32,
            24,
            14,
            0,
            0,
            0,
            0,
            0,
            0
         ]
      }
   ],
   "time_spent":[
      15,
      60
   ]
}​

Power query formula:

let
    Source = Json.Document(File.Contents("C:\Users\xxxxx\Desktop\sample.json"))[populartimes],
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"name", "data"}, {"name", "data"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Column1", "Merged", each Text.Combine(List.Transform([data],each Text.From(_)),",")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"data"}),
    #"Transposed Table" = Table.Transpose(#"Removed Columns"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Monday", type text}, {"Tuesday", type text}, {"Wednesday", type text}, {"Thursday", type text}, {"Friday", type text}, {"Saturday", type text}, {"Sunday", type text}})
in
    #"Changed Type"

16.png

Regards,

Xiaoxin Sheng

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @Anonymous ,

 

I think I have it, try the steps in this file.

PBIX

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.