Title: Asymmetry between CSV serialization of properties with `AutomationNull` or `$null` values · Issue #24699 · PowerShell/PowerShell · GitHub
Open Graph Title: Asymmetry between CSV serialization of properties with `AutomationNull` or `$null` values · Issue #24699 · PowerShell/PowerShell
X Title: Asymmetry between CSV serialization of properties with `AutomationNull` or `$null` values · Issue #24699 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. There is asymmet...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/24699
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Asymmetry between CSV serialization of properties with `AutomationNull` or `$null` values","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\nThere is asymmetry between the serialization of properties with either `AutomationNull` (`[Management.Automation.Internal.AutomationNull]::Value`) or `$null` values, that affects the following formats:\r\n\r\n- CSV\r\n- CLIXML\r\n- XML\r\n\r\nThis issue focuses on CSV. I will address (CLI)XML in a separate issue as the behavior differs.\r\n\r\nConsider the following contrived example:\r\n\r\n```powershell\r\n[pscustomobject] @{\r\n Prop = if ($false) { 'Foo' } else { $null }\r\n} | ConvertTo-Csv\r\n\r\n# \"Prop\"\r\n\r\n[pscustomobject] @{\r\n # Statement assignments have pipeline semantics, so Prop receives AutomationNull.\r\n Prop = if ($false) { 'Foo' }\r\n} | ConvertTo-Csv\r\n\r\n# \"Prop\"\r\n# \"\"\r\n```\r\n\r\nA typical PS user who is unaware of `AutomationNull` (and arguably _should not_ have to be) would reasonably expect equivalent CSV serialization. Yet, the result differs because `AutomationNull` as a property value serializes as a quoted (`\"\"`) empty field whereas `$null` serializes as unquoted. \r\n\r\n**Notes:**\r\n- Due to https://github.com/PowerShell/PowerShell/issues/17702, this issue is especially problematic when the resultant CSV data is deserialized with `ConvertFrom-Csv`/`Import-Csv` .\r\n- This issue is similar to a problem affecting JSON/`ConvertTo-Json` in _Windows PowerShell_, but has since been addressed. In the latest PS version, `AutomationNull` and `$null` both serialize as `null` in JSON.\r\n\r\n\r\n### Steps to reproduce\r\n\r\n```powershell\r\n[pscustomobject] @{ P1 = \u0026 {}; P2 = $null } | ConvertTo-Csv\r\n```\r\n\r\n### Expected behavior\r\n\r\nCSV serialization of `AutomationNull` and `$null` property values should be identical.\r\n\r\nThe result should be **_either_**:\r\n\r\n```powershell\r\n# \"P1\",\"P2\"\r\n# \"\",\"\"\r\n\r\n# Or...\r\n\r\n# \"P1\",\"P2\"\r\n# ,\r\n```\r\n\r\nDepending on whether `AutomationNull`/`$null` should both be a quoted or unquoted empty field. Note that this has deserialization implications, as noted in the aforementioned https://github.com/PowerShell/PowerShell/issues/17702 issue.\r\n\r\n\r\n### Actual behavior\r\n\r\nSerialization of `AutomationNull` and `$null` property values differs.\r\n- `AutomationNull`: `\"\"` (quoted)\r\n- `$null`: Nothing (unquoted)\r\n\r\n```powershell\r\n\"P1\",\"P2\"\r\n\"\",\r\n```\r\n\r\n\r\n### Environment data\r\n\r\n```powershell\r\nName Value\r\n---- -----\r\nPSVersion 7.5.0-rc.1\r\nPSEdition Core\r\nGitCommitId 7.5.0-rc.1\r\nOS Microsoft Windows 10.0.19045\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/surfingoldelephant","@type":"Person","name":"surfingoldelephant"},"datePublished":"2024-12-22T18:20:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/24699/PowerShell/issues/24699"}
| 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:84f977b6-f829-af38-4cf8-b75be187322f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5F8:11811:FE9D10:14DE3BD:6A5C3F15 |
| html-safe-nonce | 6738604f70cd5e40a03197d2a515034b07651074d596ef992145030528a10cf9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUY4OjExODExOkZFOUQxMDoxNERFM0JEOjZBNUMzRjE1IiwidmlzaXRvcl9pZCI6Ijc3MTQ0OTY4Mzc1NTk0MTY1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7078b68d840ffb1b6f8dee6739f52c79c0480e6de87a4cb8424203f619e25f99 |
| hovercard-subject-tag | issue:2754781598 |
| 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/24699/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b35375856c347cf7323cdbaca05ca94363ea9659c284d3c53e33eab120890cad/PowerShell/PowerShell/issues/24699 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b35375856c347cf7323cdbaca05ca94363ea9659c284d3c53e33eab120890cad/PowerShell/PowerShell/issues/24699 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | surfingoldelephant |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width