Looping through JSON array and print out same key

2019-08-21 03:33发布

Have JSON array with multiple keys of same which shows time in epoch, want to print then out and convert time to EST

{
"contents":[
      { 
        "name":"windows-Instance",
        "Buildid":"1234",
        "Buildtime":"1563350400238"
      },
      {
        "name":"linux-Instance",
        "Buildid":"1454",
        "Buildtime":"1563264000198"
      },
      {
      "name":"linux-Instance",
        "Buildid":"1278685",
        "Buildtime":"1563177600092"
       }
  ]
}

1条回答
够拽才男人
2楼-- · 2019-08-21 04:04

You can try this out to print each objects converted Epoch to current timezone:

Function Get-EpochDate ($epochDate) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddMilliseconds($epochDate)) }

$contents = (Get-Content .\test.json | ConvertFrom-Json).contents

foreach ($object in $contents) {
    $seconds = [long]$object.Buildtime
    Write-Output (Get-EpochDate $seconds)
}

Output:

Wednesday, 17 July 2019 4:00:00 PM
Tuesday, 16 July 2019 4:00:00 PM  
Monday, 15 July 2019 4:00:00 PM
查看更多
登录 后发表回答