Parsing JSON w/ PS

Welcome Forums General PowerShell Q&A Parsing JSON w/ PS

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

 
Participant
1 month ago.

  • Author
    Posts
  • #112151

    Participant
    Points: 0
    Rank: Member

    I think this code looks convoluted and messy... and I like clean code 🙂 My question, to paraphrase one of my favorite films is: "is this as good as it gets?"

  • #112159

    Participant
    Points: 19
    Rank: Member

    There are a few ways to write it, but with an object structured in that fashion, that's about it. A more pipelined version might be something like this:

    $Json | ConvertFrom-Json |
        ForEach-Object {
            foreach ($Name in $_.Value.PSObject.Properties.Name) {
                [PSCustomObject]@{
                    Name = $Name
                    Days_Remaining = $_.$Name.Days_Remaining
                }
            }
        }
  • #112163

    Participant
    Points: 0
    Rank: Member

    test

    get-command

You must be logged in to reply to this topic.