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

求助:基于playBot.id条件的JOLT转换配置

JOLT转换实现:根据playBot.id值动态控制header.billID的保留/移除

需求说明

  • 输入JSON中,若playBot.id为PROGRAM,则保留header里的billID字段
  • 若playBot.id是其他任意值,则移除header里的billID字段

输入JSON示例

{
  "playBot" : {
    "id" : "PROGRAM",
    "source" : "TestUser",
    "dateTime" : "01-09-2024 13:24:42"
  },
  "header" : {
    "activityID" : "4100",
    "memberID" : "User-ABC",
    "billID" : "1800-A"
  }
}

符合需求的JOLT转换规范

[
  {
    "operation": "shift",
    "spec": {
      "playBot": "&",
      "header": {
        "activityID": "&1.&",
        "memberID": "&1.&",
        "@(2,playBot.id)": {
          "PROGRAM": {
            "#": {
              "@(3,billID)": "&4.&3"
            }
          }
        }
      }
    }
  }
]

场景测试

场景1:playBot.id = PROGRAM

输出结果:

{
  "playBot" : {
    "id" : "PROGRAM",
    "source" : "TestUser",
    "dateTime" : "01-09-2024 13:24:42"
  },
  "header" : {
    "activityID" : "4100",
    "memberID" : "User-ABC",
    "billID" : "1800-A"
  }
}

场景2:playBot.id = TEST(非PROGRAM值)

调整后的输入:

{
  "playBot" : {
    "id" : "TEST",
    "source" : "TestUser",
    "dateTime" : "01-09-2024 13:24:42"
  },
  "header" : {
    "activityID" : "4100",
    "memberID" : "User-ABC",
    "billID" : "1800-A"
  }
}

输出结果:

{
  "playBot" : {
    "id" : "TEST",
    "source" : "TestUser",
    "dateTime" : "01-09-2024 13:24:42"
  },
  "header" : {
    "activityID" : "4100",
    "memberID" : "User-ABC"
  }
}

转换逻辑说明

  1. playBot下的所有字段直接原样保留,通过"playBot": "&"实现
  2. header里的activityID和memberID不受条件影响,始终保留
  3. 通过@(2,playBot.id)获取上层的playBot.id值,仅当该值等于PROGRAM时,才将header.billID映射到输出中;否则不会生成billID字段

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 18:32:48