ConvertFrom-JSON return array values do not seem to be unrolled on the pipeline
ConvertFrom-JSON return array values do not seem to be unrolled on the pipeline as would be expected.
For instance lets say we have this JSON:
"name" : "a"
"name" : "b"
"name" : "c"
If then I write : Get-Content -Raw test.json | ConvertFrom-Json | Measure
I expect ConvertFrom-Json to return an array that is automatically unrolled on the pipeline. However it returns a count of 1.
With the following syntax it works:
(Get-Content -Raw test.json | ConvertFrom-Json) | Measure
However, as the return value of ConvertFrom-Json is a simple array I do not expect to have to force its unrolling by using parenthesis.
The same pattern with ConvertFrom-CSV seems to work fine:
Get-Content -Raw test.csv | ConvertFrom-Csv | Measure # Count = 3
I'm not 100% sure there is a bug as my knowledge of PowerShell is quite limited but I could not find an explanation to this behaviour.
Roman Kuzmin commented
It is the same trap (probably not bug) as
PowerShell help for ConvertFrom-JSON does not help to avoid this trap. The help is even misleading because it says the output is PSCustomObject. This is not true in the case, the output is Object, not unrolled.
`ConvertFrom-Json` return one object. How original JSON looks like? Is it plain object or is it array with one object (unrolled as you propose)?
What should this command return? Three arrays or six ints?