我通過 REST 從網站中提取了大量資料并將其轉換為 JSON。我已經提取了我需要編輯的 JSON 中的特定條目。見下文
$variables = contains all the data converted to JSON
$dacpacvariable = contains the specific entry I need to edit (which is below)
{
"Id": "c1f4fe9b-3c4d-8j02-0e7x-0a6528bn192c",
"Name": "Variable1",
"Value": "abc123",
"Description": null,
"Scope": {
"Machine": [
"Machines-1"
]
},
}
我需要編輯范圍部分,如下所示:
"Scope": {
"Machine": [
"Machines-1",
"Machines-2"
]
},
然后將具有已編輯范圍的整個條目添加回較大的 JSON。
有任何想法嗎?
uj5u.com熱心網友回復:
您可以簡單地將 Attribute 替換"Machine"為其新值,例如:
$dacpacvariable = $dacpacvariable.Scope.Machine = $dacpacvariable.Scope.Machine "Machines-2"
uj5u.com熱心網友回復:
你的意思是這樣的:
$json = @'
{
"Id": "c1f4fe9b-3c4d-8j02-0e7x-0a6528bn192c",
"Name": "Variable1",
"Value": "abc123",
"Description": null,
"Scope": {
"Machine": [
"Machines-1"
]
}
}
'@ | ConvertFrom-Json
$json.Scope.Machine = 'Machines-2'
$json | ConvertTo-Json # -Depth 99 unsure how many nestings there are in the complete json
輸出:
{
"Id": "c1f4fe9b-3c4d-8j02-0e7x-0a6528bn192c",
"Name": "Variable1",
"Value": "abc123",
"Description": null,
"Scope": {
"Machine": [
"Machines-1",
"Machines-2"
]
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/490691.html
