You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConvertFrom-Json doesn't unwrap arrays on output, resulting in an extraneous wrapper JSON object with Count and Value properties on reconversion #3153
PowerShell v6.0.0-alpha (v6.0.0-alpha.15) on Darwin Kernel Version 16.4.0: Thu Dec 2222:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64
PowerShell v5.1.14393.693 on Microsoft Windows 10 Pro (64-bit; v10.0.14393)
Reacted by John Bevan, Aaron Hogue, Taliesin Sisson, Geograph and Yuriy
Steve Lee (@SteveL-MSFT): The example in this bug report now works as intended in alpha.17, but ConvertFrom-Json still unexpectedly sends an output array as a whole through the pipeline:
>'[ 1, 2 ]'|ConvertFrom-Json|% GetType |% Name
Object[]
NB: Noticed this in practice... passing the output of ConvertFrom-Json down the pipeline to a function with arguments ValueFromPipelineByPropertyName gives error The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
PetSerAl's comment is valid though; so perhaps a switch is required -UnwrapCollection to select preferred behaviour at runtime?
John Bevan (@JohnLBevan): Let's continue the conversation at #3424, which is still open (and where you've previously commented too ).
In short, my suggestion is to make ConvertFrom-Json's behavior PowerShell-friendly by default (by unwrapping, as usual), while giving users the ability to opt into array-as-single-output-object behavior with -NoEnumerate, if needed.
Activity
PetSerAl commentedon Feb 26, 2017
Workaround:
Remove-TypeData -TypeName System.Array.SteveL-MSFT commentedon Mar 16, 2017
Fixed in alpha.17 via #3231
mklement0 commentedon Mar 16, 2017
Steve Lee (@SteveL-MSFT): The example in this bug report now works as intended in alpha.17, but
ConvertFrom-Jsonstill unexpectedly sends an output array as a whole through the pipeline:Contrast this with a regular array:
SteveL-MSFT commentedon Mar 16, 2017
Michael Klement (@mklement0) can you open a new issue? thanks!
PetSerAl commentedon Mar 16, 2017
Michael Klement (@mklement0)
Should
return
[ 1 ]?mklement0 commentedon Mar 16, 2017
PetSerAl: It's a fair point - if you unwrap the array, information is lost.
But that equally applies to:
So it's weighing PowerShell's normal collection handling against preserving information about the input.
Perhaps if no one ever notices in practice that the collection is passed as a whole, the alpha.17 behavior is fine.
Not sure what the right answer is.
Steve Lee (@SteveL-MSFT): Thanks; I will, once I have clarity over whether that's indeed a problem.
JohnLBevan commentedon Feb 15, 2018
NB: Noticed this in practice... passing the output of
ConvertFrom-Jsondown the pipeline to a function with argumentsValueFromPipelineByPropertyNamegives errorThe input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.PetSerAl's comment is valid though; so perhaps a switch is required
-UnwrapCollectionto select preferred behaviour at runtime?mklement0 commentedon Feb 17, 2018
John Bevan (@JohnLBevan): Let's continue the conversation at #3424, which is still open (and where you've previously commented too ).
In short, my suggestion is to make
ConvertFrom-Json's behavior PowerShell-friendly by default (by unwrapping, as usual), while giving users the ability to opt into array-as-single-output-object behavior with-NoEnumerate, if needed.Thus, the above example would become:
Added a fix when using Convert*-Json in PowerShell version 5.1 and lo…
fix(idd): normalize PS5.1 ArrayList shape before ConvertTo-Json