Create Hashtable from JSON
$json = @{Path="C:\temp"; Filter="*.js"} | ConvertTo-Json$hashtable = @{}(ConvertFrom-Json $json).psobject.properties | Foreach { $hashtable[$_.Name] = $_.Value }
Adapted from PSCustomObject to Hashtable
A little late to the discussion here, but in PowerShell 6 (Core) there is a -AsHashtable
parameter in ConvertFrom-Json.
JavaScriptSerializer is available since .NET3.5 (may be installed on XP, included in Win7 and newer), it's several times faster than Convert-FromJSON and it properly parses nested objects, arrays etc.
function Parse-JsonFile([string]$file) { $text = [IO.File]::ReadAllText($file) $parser = New-Object Web.Script.Serialization.JavaScriptSerializer $parser.MaxJsonLength = $text.length Write-Output -NoEnumerate $parser.DeserializeObject($text)}