-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
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 }).1Expected 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
Int32Workarround
Recast the number:
$a = "1" | ConvertFrom-Json
$a = 0 + "$a"
(@{ $a = 2 }).1
2related:
- #9207 convertto-json bigint is not properly serialized
- Make Newtonsoft JsonConvert Default to Int32 Rather Than Int64
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
MarkKharitonov and antonyoni
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module