Loop to iterate through JSON

mojo27-0587 21 Reputation points
2021-04-18T10:51:25.23+00:00

[
{
"RgName": "DOTcom-dev-rg",
"Name": "dev",
"AppName": "devse-cd"
},
{
"RgName": "DOTcom-dev-rg",
"Name": "dev-cm",
"AppName": "devse-cm"
},
{
"RgName": "DOTcom-uat-rg",
"Name": "uat",
"AppName": "uatse-cd"
},
{
"RgName": "DOTcom-uat-rg",
"Name": "uat-cm",
"AppName": "uatse-cm"
}
]

Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. Anonymous
    2021-04-19T02:34:16.46+00:00

    Hi,

    You can first read the json file and convert it to a PSCustomObject.

    $file = 'd:\temp\file.json'  
    $contents = Get-Content -Path $file | ConvertFrom-Json   
    

    To get the items with specified property value you can use "Where-Object".

    $contents | Where-Object {$_.RGname -eq 'DOTcom-dev-rg'}  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.