json - 使用PowerShell遍历JSON文件

标签 json powershell

如何遍历JSON文件中的所有项目?当前代码只是将所有名称写在一行上:

Get-Content -Raw -Path c:\temp\Environments.Generic.json | ConvertFrom-Json | ForEach-Object {
    Write-Host $_.Name
}

json文件:
[
   {
      "Name":"EnableRetry",
      "Description":"Enable retry for Webservice Task",
      "Type":"Boolean",
      "Sensitive":false,
      "Value":true
   },
   {
      "Name":"FolderStageFiles",
      "Description":"Location of stage files",
      "Type":"String",
      "Sensitive":false,
      "Value":"d:\\sources\\"
   },
   {
      "Name":"FtpPassword",
      "Description":"Secret FTP password",
      "Type":"String",
      "Sensitive":true,
      "Value":"Welcome1"
   }
]

最佳答案

我最终选择对象和一个ForEach对象:

$JSON = Get-Content -Raw -Path c:\temp\Environments.Generic.json | ConvertFrom-Json

$JSON | Select-Object -Property Name,Description,Type,Sensitive,Value | ForEach-Object {
    Write-Host $_.Name $_.Value
}

关于json - 使用PowerShell遍历JSON文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43837098/

相关文章:

arrays - 替换 powershell 数组中的字符串

批处理文件中的 Powershell - 如何转义元字符?

powershell - docker exec -it my-container/bin/bash不能使我进入Powershell ISE控制台中的shell

javascript - 如何从使用 api 返回的 JSON 对象初始化 google.maps.DirectionsResult?

php - 使用显示错误的不同键创建多个元字段

php - file_get_contents ('php://input' ) 总是返回一个空字符串

python - 在Python中将json文件转换为csv不会返回任何内容?

video - 使用 PowerShell 确定目录中视频的运行时间

ios - 从 Web 界面发送 Parse JSON Push

powershell - 尝试通过 PowerShell 脚本查找并终止进程