Title: `Export-Csv`/`ConvertTo-Csv` to better stringify complex properties · Issue #20383 · PowerShell/PowerShell · GitHub
Open Graph Title: `Export-Csv`/`ConvertTo-Csv` to better stringify complex properties · Issue #20383 · PowerShell/PowerShell
X Title: `Export-Csv`/`ConvertTo-Csv` to better stringify complex properties · Issue #20383 · PowerShell/PowerShell
Description: Summary of the new feature / enhancement Although questionable, trying to put a structured object into a flat csv file, is a quite common question at stackoverflow (see e.g.: Getting System.Object[] issue for JSON Array data in output in...
Open Graph Description: Summary of the new feature / enhancement Although questionable, trying to put a structured object into a flat csv file, is a quite common question at stackoverflow (see e.g.: Getting System.Object[...
X Description: Summary of the new feature / enhancement Although questionable, trying to put a structured object into a flat csv file, is a quite common question at stackoverflow (see e.g.: Getting System.Object[...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/20383
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Export-Csv`/`ConvertTo-Csv` to better stringify complex properties","articleBody":"### Summary of the new feature / enhancement\r\n\r\nAlthough questionable, trying to put a structured object into a flat `csv` file, is a quite common question at stackoverflow (see e.g.: [Getting System.Object[] issue for JSON Array data in output in PowerShell Script](https://stackoverflow.com/questions/77186196/getting-system-object-issue-for-json-array-data-in-output-in-powershell-script)). This is often based on a misconception of the concerned structures, stingifying it to just the type name (as e.g. `System.Object[]`) is quiet pointless, instead I would expect the complex properties to have a similar value as the display format of `Format-Table`:\r\n\r\n```PowerShell\r\n$List = [PSCustomObject]@{\r\n int = 1\r\n string = 'One'\r\n Array = 1, 2\r\n HashTable = @{ '1' = 'One'; '2' = 'Two' } # Using string keys, see: #5749\r\n Object = [PSCustomObject]@{ 1 = 'One'; 2 = 'Two' }\r\n},\r\n[PSCustomObject]@{\r\n int = 2\r\n string = 'Two'\r\n Array = 3, 4\r\n HashTable = @{ '3' = 'Three'; '4' = 'Four' }\r\n Object = [PSCustomObject]@{ 3 = 'Three'; 4 = 'Four' }\r\n}\r\n```\r\n\u003csup\u003e(`2023-10-01`: Changed hashtable to string keys for reason explained at: #5749)\u003c/sup\u003e\r\n\r\n### `Format-Table` output\r\n```PowerShell\r\n$List | Format-Table\r\n\r\nint string Array HashTable Object\r\n--- ------ ----- --------- ------\r\n 1 One {1, 2} {[2, Two], [1, One]} @{1=One; 2=Two}\r\n 2 Two {3, 4} {[4, Four], [3, Three]} @{3=Three; 4=Four}\r\n```\r\n\r\n### Current `ConvertTo-Csv` output\r\n```PowerShell\r\n$List | ConvertTo-Csv\r\n\"int\",\"string\",\"Array\",\"HashTable\",\"Object\"\r\n\"1\",\"One\",\"System.Object[]\",\"System.Collections.Hashtable\",\"@{1=One; 2=Two}\"\r\n\"2\",\"Two\",\"System.Object[]\",\"System.Collections.Hashtable\",\"@{3=Three; 4=Four}\"\r\n```\r\n\r\n### Expected `ConvertTo-Csv` output (wishful thinking)\r\n```PowerShell\r\n$List | ConvertTo-Csv\r\n\"int\",\"string\",\"Array\",\"HashTable\",\"Object\"\r\n\"1\",\"One\",\"{1, 2}\",\"{[2, Two], [1, One]}\",\"@{1=One; 2=Two}\"\r\n\"2\",\"Two\",\"{3, 4}\",\"{[4, Four], [3, Three]}\",\"@{3=Three; 4=Four}\"\r\n```\r\nApart from the fact that is makes more sense, it might also help to troubleshoot and understand the situation.\r\n","author":{"url":"https://github.com/iRon7","@type":"Person","name":"iRon7"},"datePublished":"2023-09-27T12:09:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/20383/PowerShell/issues/20383"}
| 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:c3a0d939-ef52-ea4d-88ba-8a007a425b34 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CA0:28B2AB:20DDB0D:2BAEB37:6A5D69F7 |
| html-safe-nonce | 23ae7803eccee58c55645bca28f1068f27261506ef690fe35a0f61703c9a17fa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0EwOjI4QjJBQjoyMEREQjBEOjJCQUVCMzc6NkE1RDY5RjciLCJ2aXNpdG9yX2lkIjoiNDc4MzU1NTIyNjgyNDk2MDUwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 738324d5ad7cceccd56f24eb16ed29d6b4d98e91791a20eee71fd732547ebd75 |
| hovercard-subject-tag | issue:1915424003 |
| 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/20383/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9226943684d3e6fc7e9a42cac21004ceb4cc1a6eca1f7405b242570ec6c1941d/PowerShell/PowerShell/issues/20383 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9226943684d3e6fc7e9a42cac21004ceb4cc1a6eca1f7405b242570ec6c1941d/PowerShell/PowerShell/issues/20383 |
| og:image:alt | Summary of the new feature / enhancement Although questionable, trying to put a structured object into a flat csv file, is a quite common question at stackoverflow (see e.g.: Getting System.Object[... |
| 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 | 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