PowerShell – Read JSON files

As we have seen Powershell can produce JSON output.

But what if we have to read a JSON file as input.

Here we go :

[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null

$dlg = New-Object System.Windows.Forms.OpenFileDialog

$dlg.initialDirectory = """ + initialDir + """
$dlg.filter = "JSON files|*.JSON |Text Documents|*.txt | All Files|*.*"
$dlg.FilterIndex = 3
$dlg.Title = 'Select a file'
$dlg.ShowHelp = $True
$dlg.ShowDialog() | Out-Null


$j = (get-content -Raw -path $dlg.FileName) | ConvertFrom-JSON 


rv dlg,j

First of all we need to get Northwind Database to test.

The content looks like this :


Once downloaded you can run the PS Script.

It will bring up a File Selector Window


Select the Northwind.json file and look at the results.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: