#Inconsistent result of enumeration from group operator

5 messages · Page 1 of 1 (latest)

junior mesa
#

I have a list from json:

[
  {
    "id": 1,
    "name": "Alice Johnson",
    "email": "alice.j@example.com",
    "role": "admin",
    "active": true
  },
  {
    "id": 2,
    "name": "Bob Smith",
    "email": "bob84@testmail.org",
    "role": "editor",
    "active": false
  },
  {
    "id": 3,
    "name": "Charlie Davis",
    "email": "charlie.d@provider.net",
    "role": "viewer",
    "active": true
  },
  {
    "id": 4,
    "name": "Diana Prince",
    "email": "diana.p@workspace.io",
    "role": "admin",
    "active": true
  }
]

Then I found this inconsistent behaviour of group operator, I expect it to return $null since there's no entry with empty key, but the parsed list is always enumerated to a array of nulls?

(Get-Content ./list.json |  ConvertFrom-Json)."" -is [array] # true
(Get-Content ./list.json |  ConvertFrom-Json)."" | foreach { $_ -eq $null } # all true, array of nulls
(1,2,3)."" -is [array] # False, it's $null
mighty magnet
#

seems to be specific to PSCustomObject. The reproducer can be simplified to: ```powershell
@([PSCustomObject]@{ a = 1 }, [PSCustomObject]@{ a = 2 }).'anyother' -is [Array]

It doesn't exhibit for the very limited set of concrete types I've tried:
```powershell
@(@{ a = 1 }, @{ a = 2 }).'' -is [Array]
(Get-Process).'' -is [Array]
@([IPAddress]::Any, [IPAddress]::Broadcast).'' -is [Array]
#

well not a particularly encouraging issue, but it is indeed specific to PSCustomObject and is unlikely to be fixed

#

And it's documented behaviour in about_member-access_enumeration (last section of).

I think that it's going to be "won't fix" right now.

Could change, but it'd only affect PS 7+ at the very least and would need a dedicated contributor to get something like that in.