[英]How to round-trip this JSON to PSObject and back in Powershell
Powershell can't seem to correctly round-trip this JSON object: Powershell似乎无法正确地往返这个JSON对象:
{
"settings": {
"minimumApproverCount": 2,
"creatorVoteCounts": false,
"scope": [
{
"refName": "refs/heads/d14rel",
"matchKind": "Exact",
"repositoryId": "a290117c-5a8a-40f7-bc2c-f14dbe3acf6d"
}
]
}
}
Assuming $json
is a string, this command: 假设
$json
是一个字符串,这个命令:
$json | ConvertFrom-Json | ConvertTo-Json
produces the wrong JSON out of it: 从中产生错误的JSON:
{
"settings": {
"minimumApproverCount": 2,
"creatorVoteCounts": false,
"scope": [
"@{refName=refs/heads/d14rel; matchKind=Exact; repositoryId=a290117c-5a8a-40f7-bc2c-f14db
e3acf6d}"
]
}
}
Notice it gets the "scope" variable wrong. 请注意,它会使“范围”变量错误。 Is there a way to fix this?
有没有办法来解决这个问题?
Use the parameter Depth
with value 3 or larger. 使用参数
Depth
,其值为3或更大。 The default 2 is not enough, deeper data are simply converted to strings. 默认值2是不够的,更深层次的数据只是转换为字符串。
$json | ConvertFrom-Json | ConvertTo-Json -Depth 3
Output 产量
{
"settings": {
"minimumApproverCount": 2,
"creatorVoteCounts": false,
"scope": [
{
"refName": "refs/heads/d14rel",
"matchKind": "Exact",
"repositoryId": "a290117c-5a8a-40f7-bc2c-f14dbe3acf6d"
}
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.