简体   繁体   English

如何将此JSON往返于PSObject并返回Powershell

[英]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.

相关问题 Ruby中的往返JSON序列化 - Round-trip JSON serialization in Ruby Powershell 中的非损坏(具有往返能力)ConvertFrom-Json / ConvertTo-Json - Non-broken (round-trip capable) ConvertFrom-Json / ConvertTo-Json in Powershell 无法在 ASP.NET Core 中往返 JSON - 因为我做了一些愚蠢的事情 - Unable to round-trip JSON in ASP.NET Core - because I did something stupid asmx往返json - asmx round trip json 用于编写配置的数据结构格式(YAML或诸如此类)保留注释的往返解析 - Round-trip parsing of data structure format (YAML or whatnot) preserving comments, for writing configuration JSON结构无法在转换往返中幸存 - JSON structure not surviving conversion round trip 如何将 JSON 字符串转换为 PSObject? - How to convert a JSON string to PSObject? 如何使用asp .net web api,实体框架和json(代码优先)来关联对象? - How to round trip an object with relation using asp .net web api, entity framework and json (code first)? 在MVC 3应用程序中,如何进行DateTimes和TimeSpans的简单AJAX / JSON往返? - In an MVC 3 Application, how do I do a simple AJAX/JSON round trip of DateTimes and TimeSpans? .NET DateTime往返的JSON序列化不起作用 - JSON serialization of .NET DateTime round trip doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM