我正在尝试使用JSONpath来查询我的JSON对象。逻辑||或者&&运营商在工作。但是,当我尝试对谓词进行分组时,请执行逻辑||或者&&操作似乎没有起作用。 Source
E.g。
$..[?(@.book=='fiction' && @.store=='online')]
E.g。
$..[?(@.store=='online' || @.store=='offline') && (@.NER=='observation')]
第二个不起作用。关于错误位置的任何指针或者尚不支持该功能
答案 0 :(得分:2)
?应该涵盖所有条件。即整体圆形支架丢失。
正确路径:
$..[?((@.store=='online' || @.store=='offline') && (@.NER=='observation'))]
的不同示例中对其进行了验证
示例JSON:
{
"store": {
"book": [
{
"category": "fiction",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Nigel Rees",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]
}
}
具有多种条件的路径:
$..[?((@.category=='fiction' || @.author=='Nigel Rees') && (@.price < 10))]
结果:
'0' ...
'category' => "fiction"
'author' => "Nigel Rees"
'title' => "Sayings of the Century"
'price' => "8.95"
'1' ...
'category' => "fiction"
'author' => "Herman Melville"
'title' => "Moby Dick"
'isbn' => "0-553-21311-3"
'price' => "8.99"