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

JOLT转换规则调整:处理空字符串场景下的字段填充需求

JOLT转换:处理secondAccount空字符串场景的解决方案

转换规则

  • 若secondAccount存在有效值,则保留该值
  • 若secondAccount为null、空字符串或未传入,则将其设为与firstAccount相同的值

当前问题

原JOLT Spec使用modify-default-beta操作,能处理null和未传入的场景,但无法处理secondAccount为空字符串的情况——空字符串会被保留,不会替换为firstAccount的值。

解决方案

新增一步操作,先将空字符串的secondAccount替换为null,再用原有的modify-default-beta逻辑填充值。完整JOLT Spec如下:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "data": {
        "*": {
          "accounts": {
            "secondAccount": ["=isNull", "", "@(1,secondAccount)"]
          }
        }
      }
    }
  },
  {
    "operation": "modify-default-beta",
    "spec": {
      "data": {
        "*": {
          "accounts": {
            "secondAccount": "@(1,firstAccount)"
          }
        }
      }
    }
  }
]

逻辑说明

  1. 第一步(modify-overwrite-beta):使用JOLT的条件判断=isNull,当secondAccount是空字符串时,将其设为null;如果是有效值则保持不变。
  2. 第二步(modify-default-beta):对null或未传入的secondAccount,填充为firstAccount的值,同时保留有效值。

测试验证

对示例输入执行上述Spec后,输出如下:

{
  "data": [
    {
      "accounts": {
        "firstAccount": "info1",
        "secondAccount": "info1"
      }
    },
    {
      "accounts": {
        "firstAccount": "info1",
        "secondAccount": "info2"
      }
    },
    {
      "accounts": {
        "firstAccount": "info1",
        "secondAccount": "info1"
      }
    },
    {
      "accounts": {
        "firstAccount": "info1",
        "secondAccount": "info1"
      }
    },
    {
      "accounts": {
        "firstAccount": "info1",
        "secondAccount": "info1"
      }
    }
  ]
}

可以看到,原输入中secondAccount为空字符串的条目已被正确替换为firstAccount的值,同时所有有效值均被保留。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 06:30:58