Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ConvertFrom-Json -AsHashtable isn't consistently ordered #26009

@ElvenSpellmaker

Description

@ElvenSpellmaker

Prerequisites

Steps to reproduce

1.) Have a JSON with multiple keys in an object
2.) Convert to pwsh objects by using ConvertFrom-Json -AsHashtable

A random order appears even on pwsh 7.3+

Expected behavior

The ordering should be the same always

Actual behavior

Random order appears on subsequent runs

Error details

N/A - Crashes Pester Tests as Expected doesn't match half of the time

Environment data

Image:  mcr.microsoft.com/dotnet/sdk:9.0

PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
OS                             Debian GNU/Linux 12 (bookworm)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

On two different runs of the tests (dumping out the object converted back to JSON):

Image

One can see it's an OrderedHashtable but the ordering within it is totally random...

One run:

Name                           Value
----                           -----
aws:SourceAccount              <ID>
aws:SourceArn                  <ARN>


IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    OrderedHashtable                         System.Collections.H…

Another run:


Name                           Value
----                           -----
aws:SourceArn                  <ARN>
aws:SourceAccount              <ID>


IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    OrderedHashtable                         System.Collections.H…

Since 7.3+ this should be a properly ordered Hashtable with a determined order:
Issue: #17404
PR: #17405

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions