Title: Powershell Core deserializes numbers in JSON as Int64 vs Windows Powershell which does it as Int32 · Issue #14264 · PowerShell/PowerShell · GitHub
Open Graph Title: Powershell Core deserializes numbers in JSON as Int64 vs Windows Powershell which does it as Int32 · Issue #14264 · PowerShell/PowerShell
X Title: Powershell Core deserializes numbers in JSON as Int64 vs Windows Powershell which does it as Int32 · Issue #14264 · PowerShell/PowerShell
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 = ...
Open Graph 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 reprodu...
X 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 reprodu...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/14264
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Powershell Core deserializes numbers in JSON as Int64 vs Windows Powershell which does it as Int32","articleBody":"This is actually a copy of the StackOverflow issue with the same name from [@Mark](https://stackoverflow.com/users/80002/mark):\r\n[Powershell Core deserializes numbers in JSON as Int64 vs Windows Powershell which does it as Int32](https://stackoverflow.com/q/64930079/1701026)\r\n\r\n## Steps to reproduce\r\n\r\n```PowerShell\r\n$a = \"1\" | ConvertFrom-Json\r\n(@{ $a = 2 }).1\r\n```\r\n\r\n## Expected behavior\r\n\r\nReturn `2` (just like Windows PowerShell 5)\r\n\r\n## Actual behavior\r\n\r\nReturns nothing (because the actual key is of type `[Int64]` and the key \".`1`\" of type `[Int32]`)\r\n\r\nI 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:\r\n\r\n```PowerShell\r\n$a = 1\r\n$a.GetType().Name\r\nInt32\r\n```\r\n\r\n## Workarround\r\n\r\nRecast the number:\r\n\r\n```PowerShell\r\n$a = \"1\" | ConvertFrom-Json\r\n$a = 0 + \"$a\"\r\n(@{ $a = 2 }).1\r\n2\r\n```\r\n\r\n**related:** \r\n\r\n- [#9207 convertto-json bigint is not properly serialized](https://github.com/PowerShell/PowerShell/issues/9207)\r\n- [Make Newtonsoft JsonConvert Default to Int32 Rather Than Int64](https://stackoverflow.com/a/44010307/1701026)\r\n\r\n\r\n## Environment data\r\n\r\n```none\r\nName Value\r\n---- -----\r\nPSVersion 7.1.0\r\nPSEdition Core\r\nGitCommitId 7.1.0\r\nOS Microsoft Windows 10.0.19042\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```","author":{"url":"https://github.com/iRon7","@type":"Person","name":"iRon7"},"datePublished":"2020-11-25T14:39:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/14264/PowerShell/issues/14264"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ed9190fc-aaf8-3d45-6436-8beee8c711ae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A266:3D2201:D0F9D2:11BFE10:6A555F2C |
| html-safe-nonce | a070e789ae5bdbab03cfc97a9dba4094f06375fb14fc95ad5c9ee87f77fee0aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjY2OjNEMjIwMTpEMEY5RDI6MTFCRkUxMDo2QTU1NUYyQyIsInZpc2l0b3JfaWQiOiI3MzExMzM0MjI0MzEzMDE2MTA4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5cd9fc7a5400dc07cbe30a9e3001440e838f64006a3368673e54935a7c4e6e7d |
| hovercard-subject-tag | issue:750874792 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/14264/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a176c077c5757840b4a2c9e2daf45558948f56aa9712cad8421a0c5bce417c5e/PowerShell/PowerShell/issues/14264 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a176c077c5757840b4a2c9e2daf45558948f56aa9712cad8421a0c5bce417c5e/PowerShell/PowerShell/issues/14264 |
| og:image:alt | 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 reprodu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iRon7 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 73595e82546ca2415571a2031890ab16ecb3001a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width