Skip to content

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

Closed

Description

Steps to reproduce

# Create a nested object
$end = 101
$start = 1
$previous = @{
Depth = $end
Next = $null
}

($end-1)..$start | % {
$current = @{
Depth = $_
Next = $previous
}
$previous = $current
}
$previous | ConvertTo-Json -Depth $end

Expected behavior

PowerShell is able to dynamically check if we are running out of stack, and serialize objects with bigger depths.

Actual behavior

ConvertTo-Json : The maximum depth allowed for serialization is 100.
At line:1 char:13
+ $previous | ConvertTo-Json -Depth $end
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [ConvertTo-Json], InvalidOperationException
    + FullyQualifiedErrorId : ReachedMaximumDepthAllowed,Microsoft.PowerShell.Commands.ConvertToJsonCommand

Environment data

> $PSVersionTable

PS C:\windows\system32> $PSVersionTable

Name                           Value
----                           -----
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.3
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
GitCommitId                    v6.0.0-alpha.13-139-g152de408523eef294ab8592dd7740dd86c93313f
CLRVersion
PSVersion                      6.0.0-alpha
PSEdition                      Core
BuildVersion                   3.0.0.0

Activity

  1. joeyaiello commented on Feb 22, 2017

    @joeyaiello
    Contributor

    What would that look like in the output? A type name where an object would be?

  2. added
    WG-Cmdlets
    Issue-Enhancement
    on Feb 22, 2017
  3. added
    Up-for-Grabs
    on Feb 22, 2017
  4. iSazonov commented on Aug 29, 2018

    @iSazonov
    Collaborator

    Mark Kraus (@markekraus) Could you please look current status the Issue?

  5. removed
    Up-for-Grabs
    on Feb 27, 2023
  6. doctordns commented on Mar 15, 2023

    @doctordns
    Collaborator

    The Cmdlet working group has reviewed this issue. This does not appear to have been a problem in practice, and there has been little traction here (in GitHub) since the issue was first raised. We are closing this issue as Resolved-Won'tFix.

  7. added
    Resolution-Won't Fix
    on Mar 15, 2023
  8. ghost closed this as completedon Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-Won't FixWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions