0

I have this array:

[
{id: 1, name: 'foo'},
{id: 2, name: 'bar'}
]

I'm trying to filter it, but get in return all records. What am I doing wrong?:

> cat c:\temp\test.json | ConvertFrom-Json | ? { $_.name -eq 'bar'}


id name
-- ----
 1 foo
 2 bar
IttayD
  • 28,271
  • 28
  • 124
  • 178
  • 2
    it works if you save the `ConvertFrom-Json` to a $Var & then send it to `Where-Object.` it also works if you force it to parse things 1st by wrapping everything before the 2nd pipe in parens. ///// i THINK it is because the array object is being sent as a single item, not being unrolled as happens in the two working versions i tested. – Lee_Dailey Dec 29 '19 at 07:07
  • @Lee_Dailey, yes, you're right. would be interesting to know why it doesn't work in the first case. Note that in the first case, if I match to 'car', then nothing is returned. – IttayD Dec 29 '19 at 07:16
  • you would not get anything with `car` since the whole object does not have such a value in it. [*grin*] – Lee_Dailey Dec 29 '19 at 07:19
  • 1
    @Lee_Dailey is correct. If the linked post doesn't answer the question, let us know. Note that the behavior will (finally) change in v7.0 – mklement0 Dec 29 '19 at 08:37

0 Answers0