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=
PowerShell uses the two cmdlets ConvertTo-JSON and ConvertFrom-JSON to work with JSON files. The ConvertTo-JSON cmdlet converts any possible output to the JSON format and the ConvertFrom-JSON cmdlet converts the JSON input to the custom Object or the hashtable format.
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>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With