'Parsing Json in powershell
I have an automation runbook in azure that receives a json string in a variable like so:
["value1","value2"]
The problem is that I can't figure out how to handle this variable and parse it.
$array = "'$jsonInput'"
$Services = $array | ConvertFrom-Json
switch($Services)
{
value1 { $requested = $true ; break }
Default { $requested = $false }
}
Using only single quotes does not resolve my input variable. Using "'$jsonInput'" does nothing and the variable $requested returns false. I believe this is because of the use of double quotes in the input variable. What is the correct way to parse this?
If I manually enter this when testing, it works.
$array = '["value1","value2"]'
But then again, not sure how to take this json string without quotes, append the quotes and resolve the variable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
