# encoding: ascii
# api: powershell
# title: Read-JSON
# description: From greg’s repository on github.
# version: 0.1
# type: function
# author: greg zakharov
# license: CC0
# function: Read-JSON
# x-poshcode-id: 4866
# x-archived: 2014-02-09T11:19:30
# x-published: 2014-02-03T07:54:00
#
#
#requires -version 2.0
function Read-JSON {
<#
.EXAMPLE
PS C:\>Read-JSON data.json
.NOTES
Author: greg zakharov
#>
param(
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_})]
[String]$FileName
)
begin {
Add-Type -AssemblyName System.Web.Extensions
$jss = New-Object Web.Script.Serialization.JavaScriptSerializer
}
process {
try {
$jss.DeserializeObject((cat (cvpa $FileName)))
}
catch [Management.Automation.MethodInvocationException] {
Write-Host Invalid JSON primitive. -fo Red
}
}
end {}
}