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

Spring Boot Apache Camel中JQ函数IN/1不存在问题求助

JQ表达式兼容问题解决方案

问题描述

尝试在Spring Boot Apache Camel 4.0.0(搭配同版本camel-jq)中使用以下JQ表达式筛选数据:

[.links[] | select(.from == "product1") | .to] as $colors | [.hits[] | select(.id | IN($colors[])) | .name]

但遇到两个报错:

  • 使用大写IN时,提示“Function IN/1 does not exist”
  • 改用小写in时,提示“has() is not applicable to STRING”

等价替代方案

由于camel-jq依赖的JQ版本可能未支持IN/1函数,且小写in仅适用于判断对象键的存在,可采用以下两种替代写法:

方案1:使用index/1函数

利用index()判断元素是否存在于数组中(存在则返回索引值,不存在返回null):

[.links[] | select(.from == "product1") | .to] as $colors | [.hits[] | select(.id | index($colors) != null) | .name]

方案2:使用any/2函数遍历判断

通过any()遍历目标数组,匹配相等元素:

[.links[] | select(.from == "product1") | .to] as $colors | [.hits[] | select(any($colors[]; . == .id)) | .name]

内容的提问来源于stack exchange,提问作者Antônio

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 23:03:15