-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Consider removing the default -Depth value from ConvertTo-Json #8393
Copy link
Copy link
Closed
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Milestone
Metadata
Metadata
Assignees
Labels
Committee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Summary of the proposal:
Remove the default value for
-Depth100, which when exceeded, reports an error, is sufficient to prevent "runaway" JSON strings stemming from object trees with cyclic dependencies.Use
-Depthsolely at the user's discretion in order to:100levels (this could also be a solution to 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. #3181).Motivation
-Depthdefaulting to2inConvertTo-Jsonhas caused much confusion and frustration over the years; @iRon7 has recently tried to create a "canonical" post on SO, which also shows how frequently the issue is arising.Currently, an input object tree that exceeds the (default) depth doesn't cause an error, but results in near-useless
.psobject.ToString()serialization of property values that exceed the depth (see #8381 for a proposal to visualize the cut-off differently).In combination with the low default
-Depthvalue of 2, that makes for frequent user frustration, because the behavior frequently amounts to quiet de-facto failure that may not be discovered until later.The seemingly arbitrary and quiet truncation is surprising to most users, and having to account for it in every
ConvertTo-Jsoncall is an unnecessary burden.Backward-compatibility impact
The only way in which I think existing code could be impacted is in that payloads generated with
ConvertTo-Jsoncould now increase in depth (and size), if users previously relied on the implicit cut-off at depth 2 - that strikes me as a Bucket 3: Unlikely Grey Area change.