PScustom Object depth

Welcome Forums General PowerShell Q&A PScustom Object depth

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 year, 10 months ago.

  • Author
    Posts
  • #61662

    Participant
    Points: 42
    Rank: Member

    I'm getting results of a query from a TFS Api call that comes to the Shell in JSON format. Powershell then puts those results in a PScustomObject. I normally take those results and use them to perform an update to the service hosting the Json payload. The problem I sometimes have is that the resulting object is rather deep in terms of a nested JSon / object structure. Which leads me to my question.

    Tfs item I'm working with: https://www.visualstudio.com/en-us/docs/integrate/api/rm/definitions

    If I have a custom Object [pscustomobject] how can it tell what the deepest depth is so I can send that result to Invoke-webrequest -depth (deepest)

  • #61951

    Keymaster
    Points: 1,674
    Helping HandTeam Member
    Rank: Community Hero

    You really can't. .NET doesn't see this as "depth," per se; it's an object, with properties, some of which are actually collections of other objects. Until you recurse the entire thing, you can't know how far it goes. .NET just doesn't conceptualize objects that way.

  • #62100

    Participant
    Points: 42
    Rank: Member

    It's interesting that you don't have this Depth option on importing json but exporting you do.. Why is that?
    (gcm convertfrom-json ).parameters.keys
    InputObject
    Verbose
    Debug
    ErrorAction
    WarningAction
    InformationAction
    ErrorVariable
    WarningVariable
    InformationVariable
    OutVariable
    OutBuffer
    PipelineVariable

The topic ‘PScustom Object depth’ is closed to new replies.