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

Go Kazaam JSON转换返回异常结果技术咨询

Kazaam转换中Concat返回null、Coalesce无输出的问题排查与解决

问题原因

Kazaam的转换规则按顺序执行,每个操作默认基于前一个操作的输出结果处理。你的第一个shift操作将原始JSON转换为仅包含Shift字段的对象:

{ "Shift": "example1 value" }

后续concat和coalesce操作基于这个结果查找instruction.context.example1等路径,但当前输出中不存在这些字段,因此concat返回null_null,coalesce因路径不存在无输出。

解决办法

方案一:Shift操作保留后续需要的原始字段

修改shift的spec,保留instruction字段,让后续操作能在当前输出中找到目标路径:

"rules": [
    {
        "operation": "shift",
        "spec": {
            "Shift": "instruction.context.example1",
            "instruction": "instruction"
        }
    },
    {
        "operation": "concat",
        "spec": {
            "sources": [
                { "path": "instruction.context.example1" },
                { "path": "instruction.context.example2" }
            ],
            "targetPath": "Concat",
            "delim": "_"
        }
    },
    {
        "operation": "coalesce",
        "spec": {
            "Coalesce": ["instruction.context.example3[0].id"]
        }
    }
]

方案二:指定后续操作使用原始输入

在concat和coalesce操作中添加"source": "original",让这两个操作直接基于原始JSON处理,而非前一步的输出:

"rules": [
    {
        "operation": "shift",
        "spec": {
            "Shift": "instruction.context.example1"
        }
    },
    {
        "operation": "concat",
        "source": "original",
        "spec": {
            "sources": [
                { "path": "instruction.context.example1" },
                { "path": "instruction.context.example2" }
            ],
            "targetPath": "Concat",
            "delim": "_"
        }
    },
    {
        "operation": "coalesce",
        "source": "original",
        "spec": {
            "Coalesce": ["instruction.context.example3[0].id"]
        }
    }
]

预期输出

两种方案执行后都会得到正确结果:

{
    "Shift": "example1 value",
    "Concat": "example1 value_example2 value",
    "Coalesce": "example3_1_value"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 12:13:11