You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求编写Apache NiFi的Jolt规范,实现指定JSON格式转换

Apache NiFi Jolt转换规范实现指定JSON格式转换

输入JSON

{"eventid": "165","name": "High memory utilization","severity": "0","userid": "1","hosts": [{"hostid": "101","proxy_hostid": "0","host": "hostname","name": "name"}],"relatedObject": {"description": "High memory utilization","comments": "The system is running out of free memory.","uuid": ""},"tags": [{"tag": "component","value": "memory"},{"tag": "class","value": "os"},{"tag": "target","value": "linux"}]}

预期输出JSON

{"severity" : "0","name" : "High memory utilization","host" : "hostname","parameter" : "memory"}

Jolt转换规范(Shift操作)

[
  {
    "operation": "shift",
    "spec": {
      "severity": "severity",
      "name": "name",
      "hosts": {
        "0": {
          "host": "host"
        }
      },
      "tags": {
        "*": {
          "tag": {
            "component": {
              "@(2,value)": "parameter"
            }
          }
        }
      }
    }
  }
]

规范说明

  • 直接映射severity和name字段到输出对应键;
  • 从hosts数组的第一个元素(索引0)中提取host字段;
  • 遍历tags数组,匹配tag值为component的项,通过@(2,value)向上两层获取该项的value值,映射到输出的parameter字段。

内容的提问来源于stack exchange,提问作者Sathish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 14:20:35