有了下面的书店,我想找出所有符合类别‘小说’and‘奇幻’的书.

{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "adventure",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "fantasy",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}

我找到了这个示例[?(@.size in ['S', ‘M'])] here,它看起来与我想要的一模一样,但我无法让它在https://jsonpath.com上工作

这就是我try 过的:

$.store.book.[?(@.category in ['fiction','fantasy'])]

仅查找单个标准值的效果为https://jsonpath.com:

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

谢谢你给我的提示,让我知道正确的方向.

推荐答案

try 对多个条件使用logical OR(||符号).

更新后的表达式:

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

输出:

enter image description here

参考资料:

https://docs.hevodata.com/sources/engg-analytics/streaming/rest-api/writing-jsonpath-expressions/#filters

Json相关问答推荐

抓取低于w jolt的对象级别

解析JSON说函数parse_json不存在?

如何在Android中解析带有动态键和可变对象名称的改装JSON响应?

在 SQL 存储过程中使用参数 Select 值

迭代powershell双维json对象

go 语言中的 JSON 到 XML

如何将具有相同 struct 的多个JSON文件中的对象数组合并成一个数组?

如果 JSON 对象包含列表中的子字符串,则丢弃它们

使用 System.Text.Json 序列化记录成员

如何将任意 json 对象发布到 webapi

如何在 Eclipse 中安装和使用 JSON 编辑器?

Flask 请求和 application/json 内容类型

从 HttpResponse 获取 json

使用 JSON 的 javascript 深拷贝

通过 RestAssured 中的 JsonPath 访问匿名数组的元素

杰克逊:反序列化 for each 值都具有正确类型的 Map

将多个值存储在json中的单个键中

有没有一种快速的方法可以在文本编辑器中将 JavaScript 对象转换为有效的 JSON?

类型是接口或抽象类,不能实例化

如何在所有子项中查询具有特定值的属性的firebase