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
Make ConvertFrom-Csv and Import-Csv support outputting (ordered) hashtables as an alternative to custom objects #11027
Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation
I think we should also consider adding a switch to ConvertFrom-Csv and Import-Csv in order to import the data -AsHashtable for symmetry.
Note: To be a viable alternative, the output objects should be ordered hashtables ([ordered] @{}, i.e. System.Collections.Specialized.OrderedDictionary), in order to preserve the input column order.
That said, note that the existing ConvertFrom-Json -AsHashtable feature actually outputs inherently unordered [hashtable] instances.
Benefits:
As with ConvertFrom-Json -AsHashtable, you may want output objects that are easier to manipulate in terms of subsequent removal / addition of properties (entries).
Ordered hashtable instances are more lightweight than [pscustomobject] instances and should suffice in many situations.
For instance, it would enable processing of larger input datasets, in cases where [pscustomobject] output consumes inordinate amounts of memory - see #7603
Another use case: As with ConvertFrom-Json -AsHashtable, you may want output objects that are easier to manipulate in terms of subsequent removal / addition of properties (entries).
If you look OrderedDictionary implementation you find that both "easier to manipulate" and "more lightweight than [pscustomobject]" will not bring that you expect in common.
So we need to know exactly the scenario where it will benefit. While I do not see such a scenario.
We could invest more in PSObject/PSCustomObject performance - I hope there is a way to make them better.
If you look OrderedDictionary implementation you find that both "easier to manipulate" and "more lightweight than [pscustomobject]" will not bring that you expect in common.
I don't know what that means, but let's look at some scenarios, using the existing ConvertFrom-Json -AsHashtable implementation:
Note:
ConvertFrom-Json -AsHashtable uses [hashtable] instances, not ordered hashtables, but if memory serves, the performance penalty for using the ordered variety instead is fairly small.
It is known issue that adding properties to pscustomobject is relatively slow. The demo convinces me that we should invest in the area and improve psobject performance.
Without a real scenario where it is critically important, this does not convince me that we need one more parameter - cmdlets with many parameters are more likely talking about bad design or bad implementation.
The demo convinces me that we should invest in the area and improve psobject performance.
Again, a false dichotomy: that is well worth doing, but independently of what is being proposed here.
(As an aside: to be on par feature-wise, we'd then need a Remove-Property cmdlet that removes properties in place, analogous to how Add-Member adds them in place).
At a conceptual level, custom objects and hash tables can take each other's place, each with relative strengths and weaknesses, it is perfectly reasonable to support serialization / deserialization of both types:
ConvertTo-Json and ConvertTo-Json already provide that support: collections of (ordered) hash tables are supported as input, and -AsHashtable deserializes to collections of hash tables.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation
Activity
BrucePay commentedon Nov 9, 2019
What scenario would this enable?
mklement0 commentedon Nov 9, 2019
Bruce Payette (@BrucePay).
To quote from the OP:
For instance, it would enable processing of larger input datasets, in cases where
[pscustomobject]output consumes inordinate amounts of memory - see #7603mklement0 commentedon Nov 9, 2019
Another use case: As with
ConvertFrom-Json -AsHashtable, you may want output objects that are easier to manipulate in terms of subsequent removal / addition of properties (entries).iSazonov commentedon Nov 9, 2019
I do not see why I would prefer hash tables for the scenario. Rather typed output would be more useful and power.
mklement0 commentedon Nov 9, 2019
That is a false dichotomy, Ilya (@iSazonov) - both features are worth implementing - see #8862
And don't forget the convenience and speed of adding / removing entries that hashtables offer.
iSazonov commentedon Nov 9, 2019
If you look OrderedDictionary implementation you find that both "easier to manipulate" and "more lightweight than [pscustomobject]" will not bring that you expect in common.
So we need to know exactly the scenario where it will benefit. While I do not see such a scenario.
We could invest more in PSObject/PSCustomObject performance - I hope there is a way to make them better.
mklement0 commentedon Nov 9, 2019
Ilya (@iSazonov)
I don't know what that means, but let's look at some scenarios, using the existing
ConvertFrom-Json -AsHashtableimplementation:Note:
ConvertFrom-Json -AsHashtableuses[hashtable]instances, not ordered hashtables, but if memory serves, the performance penalty for using the ordered variety instead is fairly small.The code uses the
Time-Commandfunction to average 10 runs with 1001 JSON objects.The above yields the following on my macOS 10.15.1 machine:
That is:
iSazonov commentedon Nov 10, 2019
It is known issue that adding properties to pscustomobject is relatively slow. The demo convinces me that we should invest in the area and improve psobject performance.
Without a real scenario where it is critically important, this does not convince me that we need one more parameter - cmdlets with many parameters are more likely talking about bad design or bad implementation.
mklement0 commentedon Nov 10, 2019
Again, a false dichotomy: that is well worth doing, but independently of what is being proposed here.
(As an aside: to be on par feature-wise, we'd then need a
Remove-Propertycmdlet that removes properties in place, analogous to howAdd-Memberadds them in place).At a conceptual level, custom objects and hash tables can take each other's place, each with relative strengths and weaknesses, it is perfectly reasonable to support serialization / deserialization of both types:
ConvertTo-JsonandConvertTo-Jsonalready provide that support: collections of (ordered) hash tables are supported as input, and-AsHashtabledeserializes to collections of hash tables.Making
ConvertTo-Csv/Export-Csvsupport hash table input has already been green-lit in Make Export-Csv and ConvertTo-Csv support hashtables (dictionaries) #10999 (and I hope my recent clarification there makes you not object to it), so not providing the same support on the output side would be an awkward omission.microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
SteveL-MSFT commentedon Nov 19, 2025
@PowerShell/wg-powershell-cmdlets agreed this is a good feature to add