ConvertTo-Jason

Hi All, (again :slight_smile: )
I am trying to convert a cmdlet output after selecting a property and convert it to Jason.
The problem is that I get all the data but each value gets the key beside it.
I was expecting to have it grouped (in the jason format) so I get one property ‘Address’ and all the values, instead I get ‘Address’ duplicated.
Can someone help please?

PS C:\Users\xxx> Get-NcNetInterface | select Address

Address
-------
169.254.231.133
169.254.32.182
169.254.214.116


PS C:\Users\xxx> Get-NcNetInterface | select Address | ConvertTo-Json
[
    {
        "Address":  "169.254.231.133"
    },
    {
        "Address":  "169.254.32.182"
    },
    {
        "Address":  "169.254.214.116"
    }
]

Command without the convert:

PS C:\Users\xxx> Get-NcNetInterface | select Address

Address
-------
169.254.231.133
169.254.32.182
169.254.214.116

Its working as I would expect.

I don’t have the ONTAP toolkit on my machine but using Get-NetIPAddress gives similar results

PS> Get-NetIPAddress -AddressFamily IPv4 | select IPAddress | ConvertTo-Json
[
{
“IPAddress”: “127.0.0.1”
},
{
“IPAddress”: “169.254.107.168”
},
{
“IPAddress”: “169.254.76.205”
},
{
“IPAddress”: “169.254.242.182”
},
{
“IPAddress”: “10.10.54.200”
},
{
“IPAddress”: “192.168.0.6”
}
]

Your command, and mine, produce a collection of objects. Each object is converted to JSON and added to the array of JSON objects.

So in your case the first object is converted to
{
“Address”: “169.254.231.133”
}

Hey Richard,
Thanks for the reply.
I understand the the convert is doing some sort of foreach for all the collection of objects.
But in PowerShell console I can see the objects grouped to a table, I would like to select the column I want and have it converted to jason but keep the same format so I get one “Address” field with all the values it has (IPs).
Can this be achieved?