Does something like ConvertTo-TreeTable
exist?
#21343
-
If not evident, by “tree table”, I refer to what https://stackoverflow.com/q/77935915/9731176 describes. Specifically, say I have some JSON5 data like: {
"Candidate":
{
"Name": {
"3rd": "Surname",
"1st": "Forename",
"2nd": "Middle name"
},
"Date of Birth": "+1582-10-15",
"E-mail Address": "mailTo:address@domain.TLD",
"Mobile Telephone Number": "tel:+00-0000-000000",
"Blood Group": "" // Unknown
},
"Mother":
{
"Name": {
"3rd": "Surname",
"1st": "Forename",
"2nd": "Middle name"
},
"Date of Birth": "+1582-10-15",
"E-mail Address": "mailTo:address@domain.TLD",
"Mobile Telephone Number": "tel:+00-0000-000000",
},
"Father":
{
"Name": {
"3rd": "Surname",
"1st": "Forename",
"2nd": "Middle name"
},
"Date of Birth": "+1582-10-15",
"E-mail Address": "mailTo:address@domain.TLD",
"Mobile Telephone Number": "tel:+00-0000-000000",
},
} If I import this like $Values = @'
{
"Candidate":
{
"Name": {
"3rd": "Surname",
"1st": "Forename",
"2nd": "Middle name"
},
"Date of Birth": "+1582-10-15",
"E-mail Address": "mailTo:address@domain.TLD",
"Mobile Telephone Number": "tel:+00-0000-000000",
"Blood Group": "" // Unknown
},
"Mother":
{
"Name": {
"3rd": "Surname",
"1st": "Forename",
"2nd": "Middle name"
},
"Date of Birth": "+1582-10-15",
"E-mail Address": "mailTo:address@domain.TLD",
"Mobile Telephone Number": "tel:+00-0000-000000",
},
"Father":
{
"Name": {
"3rd": "Surname",
"1st": "Forename",
"2nd": "Middle name"
},
"Date of Birth": "+1582-10-15",
"E-mail Address": "mailTo:address@domain.TLD",
"Mobile Telephone Number": "tel:+00-0000-000000",
},
}
'@
$Values | ConvertFrom-JSON
$Values | ConvertFrom-JSON | Select-Object -ExpandProperty 'Candidate' This gives me firstly a useless table and then a table of a very small amount of attributes:
This isn't desirable — I want to see all of the attributes simultaneously, but with their hierarchies preserved (so merely recursively displaying all of them shan't be useful). As an example:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
Have you considered converting it to YAML for output? |
Beta Was this translation helpful? Give feedback.
-
YAML would be like
|
Beta Was this translation helpful? Give feedback.
-
The stackoverflow page you referenced doesn't work so not entirely sure what display you want but if you want to display items recursively you can use the $Values | ConvertFrom-JSON | Select-Object -ExpandProperty 'Candidate' | Format-Custom
class PSCustomObject
{
Name =
class PSCustomObject
{
3rd = Surname
1st = Forename
2nd = Middle name
}
Date of Birth = +1582-10-15
E-mail Address = mailTo:address@domain.TLD
Mobile Telephone Number = tel:+00-0000-000000
Blood Group =
} |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Per PowerShell/ConsoleGuiTools#243 (comment), I can consider https://github.com/orgs/PowerShell/discussions/21343#discussioncomment-8791165 the answer now.