Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

How to Read JSON files in PowerShell

In this tutorial, you will learn how to read JSON files in PowerShell.

Read from user.json file.

user.json file.

[
    {
        "id": 2876,
        "name": "Mohan Mukhopadhyay",
        "email": "mukhopadhyay_mohan@goodwin-kunde.co",
        "gender": "male",
        "status": "active"
    }
]
[PSCustomObject]$users = [PSCustomObject](Get-Content "./users.json" | Out-String | ConvertFrom-Json)

foreach ($user in $users) {
   # write-host $user;
    write-host "UserId: $($user.id)"
}

Read from URL

$users= Invoke-RestMethod -Uri "https://gorest.co.in/public/v2/users"

foreach ($user in $users) {
   # write-host $user;
    write-host "UserId: $($user.id)"
}

Leave a Reply