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

如何在Jolt中基于数组字段进行条件匹配并输出结果?

解决Jolt中基于数组字段的条件匹配问题

可以通过Jolt的Shift变换结合条件匹配逻辑,提取与顶层locale匹配的restaurants数组元素的value值,具体Jolt规范如下:

[
  {
    "operation": "shift",
    "spec": {
      "restaurants": {
        "*": {
          "restLocale": {
            "${locale}": {
              "@(2,value)": "value"
            }
          }
        }
      }
    }
  }
]

逻辑说明

  • restaurants.*:遍历数组中的每一个餐厅元素
  • restLocale.${locale}:判断当前元素的restLocale值是否等于顶层的locale字段值
  • @(2,value):当匹配成功时,向上回溯两层(从restLocale节点回到数组元素节点),取出该元素的value字段,赋值给输出的value键

输入示例

{
  "locale": "en_US",
  "restaurants": [
    {
      "restLocale": "en_US",
      "value": "english"
    },
    {
      "restLocale": "pr_PT",
      "value": "portugese"
    }
  ]
}

输出结果

{
  "value": "english"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 08:52:03