Title: ConvertTo-Json doesn't serialize $null · Issue #10942 · PowerShell/PowerShell · GitHub
Open Graph Title: ConvertTo-Json doesn't serialize $null · Issue #10942 · PowerShell/PowerShell
X Title: ConvertTo-Json doesn't serialize $null · Issue #10942 · PowerShell/PowerShell
Description: Conceptually related: #9231 Null values are a legitimate part of JSON, so ConvertTo-Json should be able to serialize them. Currently, ConvertTo-Json quietly ignores $nulls as a distinct input objects (but does serialize them correctly as...
Open Graph Description: Conceptually related: #9231 Null values are a legitimate part of JSON, so ConvertTo-Json should be able to serialize them. Currently, ConvertTo-Json quietly ignores $nulls as a distinct input objec...
X Description: Conceptually related: #9231 Null values are a legitimate part of JSON, so ConvertTo-Json should be able to serialize them. Currently, ConvertTo-Json quietly ignores $nulls as a distinct input objec...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/10942
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ConvertTo-Json doesn't serialize $null","articleBody":"\u003csup>Conceptually related: #9231\u003c/sup>\r\n\r\nNull values are a legitimate part of JSON, so `ConvertTo-Json` should be able to serialize them.\r\n\r\nCurrently, `ConvertTo-Json` quietly ignores `$null`s as a distinct input objects (but does serialize them correctly as a _property values_).\r\n\r\n# Steps to reproduce\r\n\r\n```powershell\r\n# OK\r\n[pscustomobject] @{ prop=$null } | ConvertTo-Json -Compress | Should -Be '{\"prop\":null}'\r\n\r\n# FAIL\r\n$null | ConvertTo-Json -Compress | Should -Be 'null'\r\nConvertTo-Json -Compress $null | Should -Be 'null'\r\n```\r\n\r\n# Expected behavior\r\n\r\nAll tests should pass.\r\n\r\n# Actual behavior\r\n\r\nThe `$null` tests fail:\r\n\r\n```\r\n^ Expected 'null', but got $null\r\n```\r\n\r\nThat is, instead of returning string `'null'`, there was _no output_.\r\n\r\n_Update_: To clarify: `$null` is generally ignored, so the following test fails too, because it returns `'[1,2]'`, not `'[1,null,2]'`:\r\n\r\n```powershell\r\n1, $null, 2 | ConvertTo-Json -Compress | Should -Be '[1,null,2]'\r\n```\r\n\r\n# Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```none\r\nPowerShell Core 7.0.0-preview.5\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2019-10-30T14:29:10Z","url":"https://github.com/PowerShell/PowerShell/issues/10942"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:a2db9312-f94a-14ef-e803-7e852c8542b7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A298:2BF055:10140A:16D8AF:6AFD5D62 |
| html-safe-nonce | 9932a86c8fe2f4a77e4999f874c3355216f0a084a9c34005bbe6a9a72c0b573b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjk4OjJCRjA1NToxMDE0MEE6MTZEOEFGOjZBRkQ1RDYyIiwidmlzaXRvcl9pZCI6IjI5MDUxMTE1Njg2NjIyMjQyMjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a915914657c093619c2fdde423d13d63d756ace998a2e0ff90d5925f1e555db7 |
| hovercard-subject-tag | issue:514716883 |
| 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/10942/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af73d312162b768e6e5c2cab08c22ce6c1356905412f7fd2ad21851ab4ac9e9d/PowerShell/PowerShell/issues/10942 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af73d312162b768e6e5c2cab08c22ce6c1356905412f7fd2ad21851ab4ac9e9d/PowerShell/PowerShell/issues/10942 |
| og:image:alt | Conceptually related: #9231 Null values are a legitimate part of JSON, so ConvertTo-Json should be able to serialize them. Currently, ConvertTo-Json quietly ignores $nulls as a distinct input objec... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| 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 | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width