2

I am using below PowerShell script to read JSON data using REST API call from source. Now I want to load the data of $Result to the Azure Blob Storage. Any idea please?

$Params = @{
 "URI" = 'https://3ea5e53b-817e-4c41-ae0b-c5afc1610f4e-bluemix.cloudant.com/test/_all_docs?include_docs=true'
}
 
$Result = Invoke-RestMethod @Params | ConvertTo-Json -Depth 9
1

1 Answer 1

4

Regarding the issue, you can use the following ways

  1. Save the JSON into one file then upload the file to Azure blob
$Params = @{
 "URI" = 'https://3ea5e53b-817e-4c41-ae0b-c5afc1610f4e-bluemix.cloudant.com/test/_all_docs?include_docs=true'
}
 
$Result = Invoke-RestMethod @Params | ConvertTo-Json -Depth 9
$Result | Out-File "D:\file.json"

$context=New-AzStorageContext -StorageAccountName "andyprivate" -StorageAccountKey ""

Set-AzStorageBlobContent -File "D:\file.json" `
  -Container "" `
  -Blob "file.json" `
  -Context $context `
  -StandardBlobTier Hot

enter image description here

  1. Directly upload to Azure blob
$Params = @{
 "URI" = 'https://3ea5e53b-817e-4c41-ae0b-c5afc1610f4e-bluemix.cloudant.com/test/_all_docs?include_docs=true'
}
 
$Result = Invoke-RestMethod @Params | ConvertTo-Json -Depth 9
Write-Host "the result is :"
$Result 

$context=New-AzStorageContext -StorageAccountName "andyprivate" -StorageAccountKey ""

$container=Get-AzStorageContainer -Name "input" -Context $context

$content = [system.Text.Encoding]::UTF8.GetBytes($Result)

$container.CloudBlobContainer.GetBlockBlobReference("my.json").UploadFromByteArray($content,0,$content.Length)

enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks Jim. Same way can we load data to Azure Cosmos DB (Mongo API)? For example: directly upload to Azure Cosmos DB
@DineshMadhup If you have a new issue, I suggest you create a new issue in StackOverflow. Then you can tell me, I will help you.
Thank you! I have created new thread, please see here stackoverflow.com/questions/66255263/…
Jim, is it possible to exclude "total_rows: 1, "offset": 0, and "rows". Because my source data doesn't contain that. I don't know from where these value get appended.
@DineshMadhup please try to the script $Result = Invoke-RestMethod @Params ($Result.PSObject.Properties.Item('rows')).value | ConvertTo-Json
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.