Unexpected array to string conversion

后端 未结 1 1321
春和景丽
春和景丽 2020-12-12 06:25

I\'m trying to pack my data into objects before displaying them with ConvertTo-Json. The test case below shows perfectly how I\'m dealing with data and what pro

1条回答
  •  [愿得一人]
    2020-12-12 06:54

    As mentioned in the comments, ConvertTo-Json will try to flatten the object structure beyond a maximum nesting level, or depth, by converting whatever object it finds beyond that depth to a string.

    The default depth is 2, but you can specify that it should go deeper with the Depth parameter:

    PS C:\> @{root=@{level1=@{level2=@("level3-1","level3-2")}}}|ConvertTo-Json
    {
        "root":  {
            "level1":  {
                "level2":  "level3-1 level3-2"
            }
        }
    }
    PS C:\> @{root=@{level1=@{level2=@("level3-1","level3-2")}}}|ConvertTo-Json -Depth 3
    {
        "root":  {
            "level1":  {
                "level2":  [
                    "level3-1",
                    "level3-2"
                ]
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题