Consider the following code:
$data = '[
{
"Name": "banana",
"Color": "yellow"
},
{
"Name": "kiwi",
"Color": "green"
},
{
"Name": "apple",
"Color": "red"
}
]'
# Returns 3 objects while only 1 was expected
$data | ConvertFrom-Json | Where-Object { $_.Name -eq 'banana' }
# Workaround, returns 1 object as expected:
($data | ConvertFrom-Json) | Where-Object { $_.Name -eq 'banana' }
Why is it not possible to use the first option? It seems like the Where-Object function does not correctly after an object is converted from json. This is happening on PowerShell version 5.1.
Are we missing something obvious here?