Skip to content

ConvertFrom-Json not properly handling an array of arrays with one element. #17398

Closed
@GingerSnap-xx

Description

@GingerSnap-xx

Prerequisites

Steps to reproduce

Create a string representing array of arrays with one root element that contains an array of two strings.
Create a string representing array of arrays with two root element that contains an array of two strings each.
Convert them from json. Call them $foo and $bar respectively.
Address $foo's first items first index and assert that it is equal to $bar's first item's first index.

The first index of the first index should be the whole string "abc", however it is collapsing it down to an array of strings, and yielding back the first index of the string e.g. "a"

PS Snippet:

$foo = ConvertFrom-Json '[["abc","def"]]'
$bar = ConvertFrom-Json '[["abc","def"],["ghi","jkl"]]'
$foo[0][0]
$bar[0][0]
$foo[0][0] -eq $bar[0][0]
$foo[0][0] -eq $bar[0][0][0]
$foo[0][0][0] -eq $bar[0][0][0]

Expected behavior

PS> $foo = ConvertFrom-Json '[["abc","def"]]'
>> $bar = ConvertFrom-Json '[["abc","def"],["ghi","jkl"]]'        
>> 
>> $foo[0][0]
>> $bar[0][0]
>> $foo[0][0] -eq $bar[0][0]
>> $foo[0][0] -eq $bar[0][0][0]
>> $foo[0][0][0] -eq $bar[0][0][0]
abc
abc
True
False
True

Actual behavior

PS> $foo = ConvertFrom-Json '[["abc","def"]]'
>> $bar = ConvertFrom-Json '[["abc","def"],["ghi","jkl"]]'        
>> $foo[0][0]
>> $bar[0][0]
>> $foo[0][0] -eq $bar[0][0]
>> $foo[0][0] -eq $bar[0][0][0]
>> $foo[0][0][0] -eq $bar[0][0][0]
a
abc
False
True
True

Error details

No response

Environment data

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.4
PSEdition                      Core
GitCommitId                    7.2.4
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

Image showing behavior in Firefox console behaving as expected just for comparison.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.Resolution-By DesignThe reported behavior is by design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions