gci | select -first 1 | ConvertTo-Json -Depth 2
gci | select -first 1 | ConvertTo-Json -Depth 3
gci | select -first 1 | ConvertTo-Json -Depth 4
one at a time. gci | select -first 1 | ConvertTo-Json -Depth 2
gci | select -first 1 | ConvertTo-Json -Depth 3
gci | select -first 1 | ConvertTo-Json -Depth 4
one at a time.Or leave it as it is and expect the user to map the complex values into hashtables. Eg in your example, make the user pipe the objects through `%{ @{ Name = $_.Name; Mode = $_.Mode; } }` first.
In any case, I don't know about other PS users, but all my command-lines that ended with ConvertTo-Json either started with ConvertFrom-Json (transforming an existing JSON file), or started with HashTables (building a JSON file from scratch) or a mix of the two. Therefore I always wanted everything to be serialized, and the `-Depth` parameter was always a nuisance.
By that logic they should also add -MaxArrayLength to make the parser stop parsing long JSON arrays, -MaxProperties to make it only parse object properties up to a limit, -MaxStringLength to only make it parser strings up to a certain length...
It's completely pointless.
EDIT: I see your point now, thank you for explaining
It can be something as trivial as "PSHashTable is allowed to serialize without limit. Every other type is limited to N levels, unless the user sets `$SERIALIZATION_LIMIT[System.Type]` to some other value." Or make the `-Depth` parameter a `Dictionary<System.Type, int>`.