gpt4 book ai didi

json - 从JSON提取值

转载 作者:行者123 更新时间:2023-12-03 14:37:04 24 4
gpt4 key购买 nike

我正在尝试使用PowerShell从JSON对象提取值,我具有以下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,并将其分配给变量。

有人知道怎么做吗 ?

最佳答案

使用Get-Content cmdlet读取文件,使用ConvertFrom-Json cmdlet进行转换,然后访问所需的属性:

$yourVariable = (Get-Content 'yourJsonFilePath.json' | ConvertFrom-Json).parameters.clusterStorageAccountName.value

关于json - 从JSON提取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42225941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com