-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
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 the ConvertTo-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:
- Json hardly preserves any (.Net) type names at all
- You can’t rebuild the object from the type name without its data.
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):
An ellipsis (plural ellipses; from the Ancient Greek: ἔλλειψις, élleipsis, 'omission' or 'falling short') is a series of dots (typically three, such as
…) that usually indicates an intentional omission of a word, sentence, or whole section from a text without altering its original meaning.
For compatibility, I would not use the Unicode ellipses character (U+2026) but simply 3 (ascii) dots: …
Taken the following commands:
$Test = @{Guid = New-Guid}
$Test.Parent = $Test
$Test | ConvertTo-Json
In stead of producing:
{
"Guid": "a274d017-5188-4d91-b960-023c06159dcc",
"Parent": {
"Guid": "a274d017-5188-4d91-b960-023c06159dcc",
"Parent": {
"Guid": "a274d017-5188-4d91-b960-023c06159dcc",
"Parent": "System.Collections.Hashtable"
}
}
}
It should produce:
{
"Guid": "a274d017-5188-4d91-b960-023c06159dcc",
"Parent": {
"Guid": "a274d017-5188-4d91-b960-023c06159dcc",
"Parent": {
"Guid": "a274d017-5188-4d91-b960-023c06159dcc",
"Parent": "..."
}
}
}