小编Swa*_*Jha的帖子

在 PowerShell 中迭代 JSON 并删除 JSON 元素

下面粘贴的是我的示例 JSON 文件。

  1. 循环所有 unqiue 属性
  2. 对于每个唯一的属性,检查 "x-visibility": "Private" 对象的值。如果这是“私人”,则删除整个对象。

我正在尝试这样做

foreach ($p in $apijson.paths.PSObject.Properties.Value) {
    $get = $p.get.'x-qlik-visibility' -eq 'Private'

    if ($get -eq 'True') {
        Write-Host 'Removing Object  :'$p
        # Remove-ItemProperty -Name $p.get
        $apijsonNew.PSObject.Properties.Remove($p)
    }
}
Run Code Online (Sandbox Code Playgroud)
{
  "swagger": "2.0",
  "info": {
    "title": "Open API specification for Repository Main API",
    "version": "20.8.0"
  },
  "basePath": "/qrs",
  "schemes": [
    "https"
  ],
  "paths": {
    "/about/api/default/analyticconnection": {
      "get": {
        "operationId": "2b781738-afd0-37a9-4248-84ec8d6be58c",
        "parameters": [
          {
            "name": "listentries",
            "in": "query",
            "required": false,
            "default": true,
            "type": "boolean", …
Run Code Online (Sandbox Code Playgroud)

powershell json

3
推荐指数
2
解决办法
9697
查看次数

标签 统计

json ×1

powershell ×1