New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConvertTo-Json
: terminate cut off branches with a ellipsis string rather than a full (.Net) type name
#8381
Comments
ConvertTo-Json
: terminate cut off branches with a ellipsis string rather than a (.Net) typeConvertTo-Json
: terminate cut off branches with a ellipsis string rather than a full (.Net) type name
Formally it is a breaking change and should be approved by PowerShell Committee. /cc @SteveL-MSFT |
My understanding is that this change wouldn't really fix the root problem with |
@louistio: Indeed it wouldn't fix the default Yes, it would provider a clearer (though not unambiguous) visual signal that something was truncated. |
As for the |
@PowerShell/powershell-committee reviewed this and it appears that the typename is the result of ToString() not being implemented so the type name is returned. Also, one can override ToString() to serialize to something more useful whereas producing "..." would limit this. |
@SteveL-MSFT for clarity, what is the recommended implimentation? if the type has ToString(), use that. If not, use ... or always use ... It is not clear from your comment. |
@markekraus, I think the recommendation is not to make any changes, based on the rationale that That said, for programmatic processing, Therefore, it comes down to:
|
Sorry if not clear, but the recommendation as @mklement0 stated is to not make any change. |
This enhancement request is related to:
Make ConvertTo-Json detect circular references
In ConvertTo-Json the max allowed depth is 100. However, we should add code to dynamically check if we are running out of stack, and serialize objects with bigger depths
Apparently almost every programmer goes through the pitfall of the default limited
-Depth
of theConvertTo-Json
cmdlet,See Sackoverflow: Unexpected ConvertTo-Json results? Answer: it has a default -Depth of 2
I guess this goes along with the fact that
ConvertTo-Json
terminates branches that are deeper than the default-Depth
(2) with a (.Net) full type name. Therefore programmers assume a bug or a cmdlet limitation and do not read the help or about.To my opinion, adding a full type name to a terminated branch doesn’t add much value, knowing that:
Meaning, that a simple ellipsis (three dots:
...
) at the end of the cut off branch could suffice and have a clearer meaning that indicates an intentional omission of additional child properties.Definition of an ellipsis (from Wikipedia):
For compatibility, I would not use the Unicode ellipses character (U+2026) but simply 3 (ascii) dots: …
Taken the following commands:
In stead of producing:
It should produce:
The text was updated successfully, but these errors were encountered: