Forum Discussion
Issue parsing a JSON
- 2 years ago
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.
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
- Gabry2 years ago
Super User
Yeah, you're right, thank for the support Anonymous .
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"