问题描述
我遵循以下JSON,如果仅在Address(数组)下存在,我想从JSON对象中删除街道。我正在尝试在Powershell中执行此操作。我可以使脚本正常工作并删除街道,但是如果地址具有streets属性,我只想运行命令的exclude行。有可能吗?
{
"Customer": [{
"id": "123"
}],"Nationality": [{
"name": "US","id": "456"
}],"address": [{
"$type": "Home","name": "Houston","streets": [{
"name": "Union","postalCode": "10"
}]
},{
"$type": "Home5","name": "Houston5"
},{
"$type": "Office","name": "Hawai","streets": [{
"name": "Rock","postalCode": "11"
}]
}
]
}
Powershell脚本
$FileContent = Get-Content -Path "Test.json" -Raw | ConvertFrom-Json
#Only want to run for address objects that contains streets
$FileContent.address = $FileContent.address | Select-Object * -ExcludeProperty streets #Only would like to run if object address has streets property
$FileContent | ConvertTo-Json
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)