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 :

CLS
[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
$dlg.ToFront

$dlg.FileName


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

$j.value

rv dlg,j

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

The content looks like this :

image

Once downloaded you can run the PS Script.

It will bring up a File Selector Window

image

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

image

Enjoy!

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: