This is actually a copy of the StackOverflow issue with the same name from @Mark:
Powershell Core deserializes numbers in JSON as Int64 vs Windows Powershell which does it as Int32
Steps to reproduce
$a = "1" | ConvertFrom-Json
(@{ $a = 2 }).1
Expected behavior
Return 2 (just like Windows PowerShell 5)
Actual behavior
Returns nothing (because the actual key is of type [Int64] and the key ".1" of type [Int32])
I am not sure whether this can be called a bug or is "by design" but my expectation (from a dynamically typed language as PowerShell Core) is that a Json number (less then [int]::MaxValue) should default to an [Int32] type, just like:
$a = 1
$a.GetType().Name
Int32
Workarround
Recast the number:
$a = "1" | ConvertFrom-Json
$a = 0 + "$a"
(@{ $a = 2 }).1
2
related:
Environment data
Name Value
---- -----
PSVersion 7.1.0
PSEdition Core
GitCommitId 7.1.0
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
This is actually a copy of the StackOverflow issue with the same name from @Mark:
Powershell Core deserializes numbers in JSON as Int64 vs Windows Powershell which does it as Int32
Steps to reproduce
Expected behavior
Return
2(just like Windows PowerShell 5)Actual behavior
Returns nothing (because the actual key is of type
[Int64]and the key ".1" of type[Int32])I am not sure whether this can be called a bug or is "by design" but my expectation (from a dynamically typed language as PowerShell Core) is that a Json number (less then
[int]::MaxValue) should default to an[Int32]type, just like:Workarround
Recast the number:
related:
Environment data