json JOLT规范-根据字典列表的键/值对值进行排序

mhd8tkvw  于 2022-12-20  发布在  其他
关注(0)|答案(1)|浏览(162)

JOLT规范的后续问题-是否可以根据字典列表的键/值对值进行排序?
添加更多选项如何:
JSON输入:

{
  "list": [
    {
      "tags": [
        {
          "scope": "",
          "tag": "TAG_VM"
        },
        {
          "scope": "",
          "tag": "TAG_HOST"
        },
        {
          "scope": "",
          "tag": "TAG_ROLE_DNS"
        },
        {
          "scope": "",
          "tag": "TAG_ROLE_AD"
        },
        {
          "scope": "",
          "tag": "TAG_USER_INSIDE"
        },
        {
          "scope": "",
          "tag": "TAG_USER_OUTSIDE"
        },{
          "scope": "",
          "tag": "TAG_INTERNET_TRUE"
        }
      ]
    }
  ],
  "result_count": 1,
  "sort_by": "name"
}

疾病输出:

{
  "role1" : "DNS",
  "role2" : "AD",
  "user1" : "INSIDE",
  "user2" : "OUTSIDE",
  "internet" : "TRUE"

}

多谢帮忙!

ogq8wdun

ogq8wdun1#

类似的逻辑将与构建和使用多个独立的数组沿着工作,方法是在这种情况下使其更具动态性,例如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "*": {
              "*": {
                "TAG_*_*": {
                  "$": "&(1,1).&(1,2)"
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "$": "&2"
        },
        "#0": "&1"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "@": "&2&"
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*0": ""
    }
  },
  { // exchange key-value pairs to be able to convert keys to lower case 
    "operation": "shift",
    "spec": {
      "*": {
        "$": "@(0)"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=toLower(@(1,&))"
    }
  },
  { // exchange key-value pairs back to the original
    "operation": "shift",
    "spec": {
      "*": {
        "$": "@(0)"
      }
    }
  }
]

相关问题