0

I have a following JSON file/blob in the Azure Storage as students.json. Using Powershell, I want to read the contents of the file, student's FirstName and LastName where the MainSubject is Math

{
  "college": {
    "students": [
      {
        "FirstName": "abc",
        "LastName": "xyz",
        "MainSubject": "Computers"
      },
      {
        "FirstName": "lmn",
        "LastName": "opq"
        "MainSubject": "Math"        
      }
    ]
  }
}

1
  • Do you have a question about a code of yours that isnt working regarding this? Commented Nov 28, 2022 at 6:49

1 Answer 1

1

I have reproduced in my environment and got expected results as below and followed Microsoft-Document and Thanks to @ Ivan Yang's SO-thread :

    $accountName = "rithwikstor"
    $accountKey = "XX"
    $containerName = "rithwik"
    $blobName = "emo.json"
    $context = New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
    $container_client = Get-AzStorageContainer -Name $containerName -Context $context
    $source_blob_client = $container_client.CloudBlobContainer.GetBlockBlobReference($blobName)
    $download_file = $source_blob_client.DownloadText()
    $jsonContent = $download_file | ConvertFrom-Json
    
    
    $ans=$jsonContent.college | ConvertTo-json
    $res= $ans | ConvertFrom-json
    $res.students | where{$_.Mainsubject -eq 'Math'}
    $emo=$res.students | where{$_.Mainsubject -eq 'Math'}
    $emo | Select-Object * -ExcludeProperty MainSubject


XX is the Storage account key. Got it from below:

enter image description here

Output:

enter image description here

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

2 Comments

Thanks. But is there a way to achieve the results without downloading the file?
@EZR, This is the way how I do it and I don't think there is any other way ,if there any i would like to know it.

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.