Reputation: 1355
I am using Powershell 2.0 (cannot make an upgarde to V3.0 as of now) and I want to read the JSON object from bellow:
{"DevResults":[{"TechnologyName":"AD","RuleName":"SOA account (user logon/display name)","OutputValue":"SOADevClientCenter"},
{"TechnologyName":"AD","RuleName":"SOA account (pre-Windows 2000)","OutputValue":"SOADevCliCen"},
"ProdResults":[{"TechnologyName":"AD","RuleName":"SOA account (user logon/display name)","OutputValue":"SOAClientCenter"},
{"TechnologyName":"AD","RuleName":"BPM Service Account (pre-Windows 2000)","OutputValue":"BPM_CliCen_05"}]}
Upvotes: 17
Views: 20642
Reputation: 24330
You probably have the System.Web.Extensions available, and as such you can load that assembly and use the JSON parser that is available. Here is a quick sample:
[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$json = "{a:1,b:2,c:{nested:true}}"
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$obj = $ser.DeserializeObject($json)
Reference: http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
Upvotes: 30