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

NiFi JOLT转换规范需求:合并双键为单键并指定值来源

正确的NiFi JOLT转换规范

输入示例

{
  "options": [
    {
      "method": "GET",
      "type": "USER",
      "flag": true,
      "updateSource": "DB"
    },
    {
      "method": "POST",
      "type": "ORDER",
      "flag": false,
      "updateSource": "API"
    }
  ]
}

目标输出示例

{
  "GET_USER": true,
  "GET_USER_updateSource": "DB",
  "POST_ORDER": false,
  "POST_ORDER_updateSource": "API"
}

JOLT转换规范

[
  {
    "operation": "shift",
    "spec": {
      "options": {
        "*": {
          "flag": "@(1,method)_@(1,type)",
          "updateSource": "@(1,method)_@(1,type)_updateSource"
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "options": ""
    }
  }
]

转换逻辑说明

  • shift操作遍历options数组的每个元素:
    • 通过@(1,method)_@(1,type)拼接出method_type格式的键,将flag的值映射到该键下
    • 拼接method_type_updateSource格式的键,将updateSource的值映射到对应键下
  • remove操作清理原有的options数组,仅保留转换后的目标键值对

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 16:42:31