Forum Discussion
JSON headers at top of file not with data
Hi, I am new to bringing data in via api. I have a json report file brought into power query via api. After clearing out the rows that are just titles etc I am left with this:
My issue is the headers are one list and the data is a seperate one. Other files I have used have had the headers repeat in the data but this one does not. I want to get to a flat table but I can't work out how to seperate the headers and data.
When I click the two arrows I get to this stage:
This has the headers at the top and the rows still as a list below.
Can anyone offer a solution please?
let Source = Json.Document(File.Contents("C:\Users\xxx\Downloads\response.txt")), #"Converted to Table" = Table.FromList( Source[rows], Splitter.SplitByNothing(), null, null, ExtraValues.Error ), #"Extracted Values" = Table.TransformColumns( #"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), "|"), type text} ), #"Split Column by Delimiter" = Table.SplitColumn( #"Extracted Values", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), Source[columnNames] ) in #"Split Column by Delimiter"
4 Replies
- lbendlin
Super User
There are Power Query functions for that. Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216 - KrisCartNew Member
Hi lbendlin,
Thanks for the pointers. File attached, Sample JSON
I have stripped it down to 2 records for ease and have changed any business data.
If you could point me towards any suitable function that would be great. It seems such a simple thing that I know I am missing something.
Thanks
- lbendlin
Super User
let Source = Json.Document(File.Contents("C:\Users\xxx\Downloads\response.txt")), #"Converted to Table" = Table.FromList( Source[rows], Splitter.SplitByNothing(), null, null, ExtraValues.Error ), #"Extracted Values" = Table.TransformColumns( #"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), "|"), type text} ), #"Split Column by Delimiter" = Table.SplitColumn( #"Extracted Values", "Column1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), Source[columnNames] ) in #"Split Column by Delimiter"- KrisCartNew Member
Thanks, the original source was an api but I addressed that by swapping the code line with the filename for the four lines of the api call.
It all seems to be working now - thank you very much.