Json – Reading json response in windows power shell

jsonpowershell

I am using power shell code as:

   $web_client = new-object system.net.webclient
    $build_info=web_client.DownloadString("http://<URL>")
    $suitevm_build_number=
    $suitevmCLN=
    $webapp_build=
    $stats_build=

Output in browser while hitting http:// is:

{"message":null,"changeset":"340718","branch":"main","product":"productname","buildNumber":"1775951","todaysDate":"28-4-2014"}

What should I write the power shell code to get:

  $suitevm_build_number=
    $suitevmCLN=
    $webapp_build=
    $stats_build=

Best Answer

You're question is very unclear. If you have Powershell 3 or later, you can use ConvertFrom-JSON to convert the JSON-response to a object.

$build_info=$web_client.DownloadString("http://<URL>") | ConvertFrom-Json

Ex of output:

$build_info

message     : 
changeset   : 340718
branch      : main
product     : productname
buildNumber : 1775951
todaysDate  : 28-4-2014

With PS 3+ you could also replace the webclient with Invoke-RestMethod as shown by @RickH.

$build_info = Invoke-RestMethod -Uri "http://<URL>"