Question:
1 2 3 4 |
$json = ConvertFrom-Json "{key:true}" $key = "key" Write-Host $json[$key] |
I’d like that to print true but it doesn’t. I know
$json.key
would work. Can this be done?
Answer:
If you know that $json.key
would work, then why you’re switching from dot to square brackets?
All these will work:
1 2 3 4 5 6 7 |
$json = ConvertFrom-Json "{key:true}" $key = "key" Write-Host $json.$key Write-Host $json.$($key) Write-Host $json."$key" |