从JSON提取值 [英] Extract value from JSON
本文介绍了从JSON提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用PowerShell从JSON对象提取值,我具有以下JSON:
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"
}
}
}
在这里,我想使用powershell从此文件中提取clusterStorageAccountName
,并将其分配给变量.
Here I want to extract clusterStorageAccountName
from this file using powershell, and assign it to variable.
有人知道该怎么做吗?
推荐答案
使用Get-Content
cmdlet读取文件,使用ConvertFrom-Json
cmdlet转换文件,然后访问所需的属性:
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
这篇关于从JSON提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文