I am trying to use PowerShell to extract value from JSON object, I have the following JSON:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterName": {
"value": "hbasehd35"
},
"location": {
"value": "East US 2"
},
"clusterType": {
"value": "hbase"
},
"clusterVersion": {
"value": "3.5"
},
"clusterWorkerNodeCount": {
"value": 5
},
"subnetName": {
"value": "hbase-subnet"
},
"headNodeSize": {
"value": "Standard_D12_v2"
},
"workerNodeSize": {
"value": "Standard_D12_v2"
},
"zookeeperSize": {
"value": "Large"
},
"clusterStorageAccountName": {
"value": "hbasestorage"
},
"storageAccountType": {
"value": "Standard_GRS"
},
"Environment": {
"value": "test"
}
}
}
Here I want to extract clusterStorageAccountName
from this file using powershell, and assign it to variable.
Anyone know how to do this ?
Use the Get-Content
cmdlet to read the file, convert it using the ConvertFrom-Json
cmdlet and just access the property you want:
$yourVariable = (Get-Content 'yourJsonFilePath.json' | ConvertFrom-Json).parameters.clusterStorageAccountName.value
I don't know why, but the approach from message above don't work for me. But works just getting key that you need by key after "ConvertFrom-Json" command, e.g.:
$yourVariable = (Get-Content 'yourJsonFilePath.json' | ConvertFrom-Json).clusterStorageAccountName
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