Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Json Object in Powershell 2.0

I am using Powershell 2.0 (cannot make an upgarde to V3.0 as of now) & I want to read the below Json object.

"{\"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\"}]}"

Can you please help me with the same.

Thanks.

like image 849
0nir Avatar asked Jul 11 '13 19:07

0nir


People also ask

Can PowerShell parse JSON?

PowerShell is a great tool to use for manipulating JSON which is used throughout Azure. Have fun scripting! Additional reading: 7.1: ConvertFrom-Json (Microsoft.

What is ConvertTo-JSON?

Description. The ConvertTo-Json cmdlet converts any . NET object to a string in JavaScript Object Notation (JSON) format. The properties are converted to field names, the field values are converted to property values, and the methods are removed.


Video Answer


1 Answers

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

like image 110
Goyuix Avatar answered Sep 24 '22 05:09

Goyuix