I am trying to install libraries on my databricks cluster, based on the external json file.
The file is constructed like this:
{"libraries":[
{
"pypi": {
"package": "sparkmeasure==0.14.0"
}
},
{
"maven": {
"coordinates": "azureml-core==1.20.0"
}
}
]
}
Then I am trying to read the file, build the request body and invoke the rest method.
$json = Get-Content $filePath| Out-String | ConvertFrom-Json -Depth 99
$Region = $Region.Replace(" ", "")
$uri = "https://$Region.azuredatabricks.net/api/2.0/libraries/install"
$Body = @{ "cluster_id" = $ClusterId }
$Body['libraries'] = $json.libraries
$BodyText = $Body | ConvertTo-Json
Write-Output $BodyText
Invoke-RestMethod -Uri $uri -Body $BodyText -Method 'POST' -Headers @{ Authorization = $InternalBearerToken }
This is the output body I am getting:
{
"libraries": [
{
"pypi": "@{package=sparkmeasure==0.14.0}"
},
{
"maven": "@{coordinates=azureml-core==1.20.0}"
}
],
"cluster_id": "myclusterid"
}
However, I only need to grab the value from the file, so my expected result looks like that:
{
"libraries": [
{
"pypi": {
"package": "sparkmeasure==0.14.0"
}
},
{
"maven": {
"coordinates": "azureml-core==1.20.0"
}
}
],
"cluster_id": "myclusterid"
}
I am very new to PowerShell, so I was wondering if there is some simple way to preserve the structure of the json file instead of having those nested structures as arrays?