Forum Discussion
Importing multiple JSON files int PBI (Data Source = Admin API GetDatasourcesAsAdmin)
- 1 year ago
Here is a way to check for record vs. list as part of your parsing. As stated previously, you can simply wrap the records you find into a list and then treat all outputs the same.
let Source = Folder.Files("<local file location with your json examples saved>"), //parse the json, if a single record, wrap in list so they are all list of records ParseJson = List.Transform( Source[Content] , //binaries are in "Content" column each let json = Json.Document( _ ), valTypeIsRecord = Type.Is( Value.Type( json ), type record ) in if valTypeIsRecord //if it's a record then { json } //wrap in a list else json //otherwise leave as is ), //list of list of records --> list of records CombineRecords = List.Combine( ParseJson ), //uniform transformation - Table.FromRecords is designed for list of records ToTable = Table.FromRecords( CombineRecords, //provide exact types here so we don't have to later type table [ datasourceType=text, connectionDetails=[server=text,database=text], datasourceId=text, gatewayId=text ] ), ExpandConnectionDetails = Table.ExpandRecordColumn( ToTable, "connectionDetails", {"server", "database"}, {"connectionDetails.server", "connectionDetails.database"} ) in ExpandConnectionDetailsPics of steps so you can see better what's going on:
Hi gwhiteman , I think the issue arises from inconsistent JSON structures where single connections are objects, and multiple connections are arrays.You can preprocess the JSON files to ensure all entries are wrapped as arrays or adjust the Power Query logic in Power BI to dynamically handle both records and lists You could also use Power BI REST API to handle this
If this post helped please do give a kudos and accept this as a solution
Thanks In Advance
Hi Akash,
Thanks for you feed back, I came to the same conclusion however I was not sure how to get around this neatly. I have manage to work around this using 2 different power queries filtering out errors, then merging them into a single table. It is not cleanest solutions however it does work as far as I can tell. I am also keen to understand how I can "use Power BI REST API to handle this"? I am not the best with PowerShell commands.
- MarkLaf1 year ago
Super User
Here is a way to check for record vs. list as part of your parsing. As stated previously, you can simply wrap the records you find into a list and then treat all outputs the same.
let Source = Folder.Files("<local file location with your json examples saved>"), //parse the json, if a single record, wrap in list so they are all list of records ParseJson = List.Transform( Source[Content] , //binaries are in "Content" column each let json = Json.Document( _ ), valTypeIsRecord = Type.Is( Value.Type( json ), type record ) in if valTypeIsRecord //if it's a record then { json } //wrap in a list else json //otherwise leave as is ), //list of list of records --> list of records CombineRecords = List.Combine( ParseJson ), //uniform transformation - Table.FromRecords is designed for list of records ToTable = Table.FromRecords( CombineRecords, //provide exact types here so we don't have to later type table [ datasourceType=text, connectionDetails=[server=text,database=text], datasourceId=text, gatewayId=text ] ), ExpandConnectionDetails = Table.ExpandRecordColumn( ToTable, "connectionDetails", {"server", "database"}, {"connectionDetails.server", "connectionDetails.database"} ) in ExpandConnectionDetailsPics of steps so you can see better what's going on:
- Akash_Varuna1 year ago
Super User
Hi gwhiteman could you try these steps please
Register an App in Azure AD: Register your app in Azure and provide Power BI Service permissions.
Authenticate: Use Postman or PowerShell to generate an access token for secure API access.
Use REST API:
- Retrieve datasets: GET https://api.powerbi.com/v1.0/myorg/datasets
- Trigger refresh: POST https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/refreshes
- Automate with PowerShell:
$token = "YourAccessToken"
$headers = @{ "Authorization" = "Bearer $token" }
Invoke-RestMethod -Uri "https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/refreshes" -Method Post -Headers $headers