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

JSONPath筛选fiction/fantasy分类图书遇语法问题,求解决方法

JSONPath多类别筛选解决方案

问题原因

  1. 你使用的JSONPath工具实现的是Stefan Goessner原始JSONPath规范,该规范不支持in操作符,因此[?(@.category in ['fiction','fantasy'])]这类写法无法生效。
  2. 你尝试的表达式$.store.book.[?(@.category in ['fiction','fantasy'])]中,book后面多了一个多余的.,属于语法错误,会导致表达式解析失败。

可行表达式写法

直接用逻辑或(||)拼接多个相等判断,同时去掉book后的多余点:

$.store.book[?(@.category == 'fiction' || @.category == 'fantasy')]

筛选结果

使用该表达式处理你提供的书店数据,会返回以下两本符合条件的图书:

[
  {"category": "fiction","author": "Evelyn Waugh","title": "Sword of Honour","price": 12.99},
  {"category": "fantasy","author": "J. R. R. Tolkien","title": "The Lord of the Rings","isbn": "0-395-19395-8","price": 22.99}
]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 03:41:28