Skip to content

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": "[email protected]",
        "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)"
}
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments