Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
I have an issue with parsing a JSON.
I'm making an API call using the web connector, and it returns a JSON. Each record in the JSON has 4 fields, 2 are keys, and 2 are descriptions. Now, when I make the call directly from the browser, it returns all the data in all fields. However, when I parse the JSON from Power BI (tried both desktop and service), I get all the data for the ID fields, but for the description fields, I only get data in 2 records while all others remain empty. How is this possible? I don't understand what the problem might be. Can anyone help?
Solved! Go to Solution.
I've identified the issue: it was a missing header. The browser automatically filled in this header, whereas PowerBI did not.
I still don't understand the impact of this header, as it was the Accept-Language header, but now it works.
I've identified the issue: it was a missing header. The browser automatically filled in this header, whereas PowerBI did not.
I still don't understand the impact of this header, as it was the Accept-Language header, but now it works.
Do anyone have any clue?
Hi @Gabry ,
Could you share a snippet of the JSON structure (with any sensitive information redacted)?
Is it losing field data in the expand step or in the parsing json step(It would be nice to have the m-code for this step)?
This information will help in pinpointing the issue more accurately.
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum -- China Power BI User Group
Yeah, you're right, thank for the support @v-cgao-msft .
This is the M code:
let
Source = Csv.Document(Web.Contents("http://*********/sap/opu/odata/sap/ZA_PROFIT_CENTER_HIER_CDS/ZA_PROFIT_CENTER_HIER?$format=json"),[Delimiter=";", Columns=1, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Parsed JSON" = Table.TransformColumns(#"Changed Type",{},Json.Document),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Parsed JSON", "Column1", {"d"}, {"Column1.d"}),
#"Expanded Column1.d" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1.d", {"results"}, {"Column1.d.results"}),
#"Expanded Column1.d.results" = Table.ExpandListColumn(#"Expanded Column1.d", "Column1.d.results"),
#"Expanded Column1.d.results1" = Table.ExpandRecordColumn(#"Expanded Column1.d.results", "Column1.d.results", {"SetID", "SetDescription", "ChildSetID", "ChildSetDescription"}, {"SetID", "SetDescription", "ChildSetID", "ChildSetDescription"})
I've tried to change the Encoding with 1200 and 65001 (nothing change)
I've tried to use json like this
let
Source = Json.Document(Web.Contents("http://***********/sap/opu/odata/sap/ZA_PROFIT_CENTER_HIER_CDS/ZA_PROFIT_CENTER_HIER?$format=json")),
#"Conversione in tabella eseguita" = Table.FromRecords({Source}),
#"d espansa" = Table.ExpandRecordColumn(#"Conversione in tabella eseguita", "d", {"results"}, {"d.results"}),
#"d.results espansa" = Table.ExpandListColumn(#"d espansa", "d.results"),
#"d.results espansa1" = Table.ExpandRecordColumn(#"d.results espansa", "d.results", {"__metadata", "SetID", "SetDescription", "ChildSetID", "ChildSetDescription"}, {"d.results.__metadata", "d.results.SetID", "d.results.SetDescription", "d.results.ChildSetID", "d.results.ChildSetDescription"}),
#"d.results.__metadata espansa" = Table.ExpandRecordColumn(#"d.results espansa1", "d.results.__metadata", {"id", "uri", "type"}, {"d.results.__metadata.id", "d.results.__metadata.uri", "d.results.__metadata.type"}),
I've tried to read the json with python.
I've tried to remove the ?$format=json at the and of the api call, then it gives an xml with the same issue.
BUT if I open this API with the browser I get all the data.
Those are the first 2 records of the Json, as you can see the first one have no data on the field "ChildSetDescription". But the same record has data if I open with the browser.
The second record has all the data (there are only 3 records with all the data, the others don't)
{
"d": {
"results": [
{
"__metadata": {
"id": "http://***********/sap/opu/odata/sap/ZA_PROFIT_CENTER_HIER_CDS/ZA_PROFIT_CENTER_HIER('Y001_PC')",
"uri": "http://***********/sap/opu/odata/sap/ZA_PROFIT_CENTER_HIER_CDS/ZA_PROFIT_CENTER_HIER('Y001_PC')",
"type": "ZA_PROFIT_CENTER_HIER_CDS.ZA_PROFIT_CENTER_HIERType"
},
"SetID": "Y001_PC",
"SetDescription": "Controlling Area",
"ChildSetID": "Y001_BGAT",
"ChildSetDescription": ""
},
{
"__metadata": {
"id": "http://***********/sap/opu/odata/sap/ZA_PROFIT_CENTER_HIER_CDS/ZA_PROFIT_CENTER_HIER('Y001_PC')",
"uri": "http://***********/sap/opu/odata/sap/ZA_PROFIT_CENTER_HIER_CDS/ZA_PROFIT_CENTER_HIER('Y001_PC')",
"type": "ZA_PROFIT_CENTER_HIER_CDS.ZA_PROFIT_CENTER_HIERType"
},
"SetID": "Y001_PC",
"SetDescription": "Controlling Area",
"ChildSetID": "Y001_ST",
"ChildSetDescription": "Structure"
},
{
This is how it looks from power query:
Instead if I open it with the browser, save as JSON, then open the Json file with power query:
This is the M code to open the local json file saved from the browser
let
Origine = Json.Document(File.Contents("C:\Users\***************.json")),
#"Conversione in tabella" = Record.ToTable(Origine),
#"Tabella Value espansa" = Table.ExpandRecordColumn(#"Conversione in tabella", "Value", {"results"}, {"Value.results"}),
#"Tabella Value.results espansa" = Table.ExpandListColumn(#"Tabella Value espansa", "Value.results"),
#"Tabella Value.results espansa1" = Table.ExpandRecordColumn(#"Tabella Value.results espansa", "Value.results", {"__metadata", "SetID", "SetDescription", "ChildSetID", "ChildSetDescription"}, {"Value.results.__metadata", "Value.results.SetID", "Value.results.SetDescription", "Value.results.ChildSetID", "Value.results.ChildSetDescription"})
in
#"Tabella Value.results espansa1"
I've tried now to use the same identical code but with the API instead of the local file and it doesn't work:
let
Origine = Json.Document(Web.Contents("http://*************/sap/opu/odata/sap/ZA_PROFIT_CENTER_HIER_CDS/ZA_PROFIT_CENTER_HIER?$format=json")),
#"Conversione in tabella" = Record.ToTable(Origine),
#"Tabella Value espansa" = Table.ExpandRecordColumn(#"Conversione in tabella", "Value", {"results"}, {"Value.results"}),
#"Tabella Value.results espansa" = Table.ExpandListColumn(#"Tabella Value espansa", "Value.results"),
#"Tabella Value.results espansa1" = Table.ExpandRecordColumn(#"Tabella Value.results espansa", "Value.results", {"__metadata", "SetID", "SetDescription", "ChildSetID", "ChildSetDescription"}, {"Value.results.__metadata", "Value.results.SetID", "Value.results.SetDescription", "Value.results.ChildSetID", "Value.results.ChildSetDescription"})
in
#"Tabella Value.results espansa1"
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
68 | |
55 | |
43 | |
28 | |
22 |