Skip to content

ConvertFrom-Json should have a -AsOrderedDictionary #17404

@SteveL-MSFT

Description

@SteveL-MSFT

Summary of the new feature / enhancement

Currently, when using ConvertFrom-Json -AsHashtable, you get an unordered hashtable where the properties don't match the order defined in the JSON.

'{ "a": 0, "b": 1, "c": 2 }' | ConvertFrom-Json -AsHashtable

Expected:

Name                           Value
----                           -----
a                              0
b                              1
c                              2

Actual:

Name                           Value
----                           -----
c                              2
b                              1
a                              0

Proposed technical implementation details (optional)

Proposal is to make -AsHashtable actually return an OrderedDictionary. I believe from PS script usage, there should not be any impact even if the type changes. Alternative would be to add a -Ordered switch used with -AsHashtable or a -AsOrderedDictionary in a different parameterset from -AsHashtable but this seems unnecessary and most of the time, I would expect users converting from JSON would want to preserve order making it more readable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions