简体   繁体   English

Powershell 7.2.5 ConvertFrom-Json 将数组作为一个对象输出

[英]Powershell 7.2.5 ConvertFrom-Json Outputting Array as One Object

I'm using the AWS CLI command aws iam list-users in Powershell 7.2.5 and trying to convert the output from JSON to a Powershell Object.我在 Powershell 7.2.5 中使用 AWS CLI 命令aws iam list-users并尝试将输出从 JSON 转换为 Powershell 对象。

The JSON output of the above command looks like this (actual values omitted):上述命令的 JSON 输出如下所示(省略实际值):

{
    "Users": [
        {
            "Path": "/",
            "UserName": "username1",
            "UserId": "userid1",
            "Arn": "arnid1",
            "CreateDate": "createddate"
        },
        {
            "Path": "/",
            "UserName": "username2",
            "UserId": "userid2",
            "Arn": "arnid2",
            "CreateDate": "createddate"
        },
        {
            "Path": "/",
            "UserName": "username3",
            "UserId": "userid3",
            "Arn": "arnid3",
            "CreateDate": "createddate"
        }
    ]
}

When I try and run the following code to create an array of Powershell Objects the output comes out as one Object.当我尝试运行以下代码来创建一个 Powershell 对象数组时,输出作为一个对象出现。

$users = ConvertFrom-Json -InputObject $usersJson

Users
-----
{@{Path=/; UserName=username1; UserId=userid1; Arn=arnid1; CreateDate=createddate}, @{Path=/; UserName=username2; UserId=userid2; Arn=arnid2; CreateDate=createddate}, @{Path=/; UserName=username3; UserId=userid3; Arn=arnid3; CreateDate=createddate}}

Have read over countless posts and am now at a loss of what to do.已经阅读了无数的帖子,现在我不知道该怎么办。

Any help would be greatly appreciated.任何帮助将不胜感激。

Santiago 's comment was correct: Santiago评论是正确的:

$users.Users shows all the entries as individual objects. $users.Users将所有条目显示为单个对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM