2016-11-05 39 views
1

下面給出的JSON:檢查多個存在的條件,JSONpath

{ 
    "store": { 
     "book": [ 
      { 
       "author": "Nigel Rees", 
       "title": "Sayings of the Century" 
      }, 
      { 
       "category": "fiction", 
       "title": "Sword of Honour", 
       "price": 12.99 
      } 
     ] 
} 

我如何構建檢索有categorypricetitle元素book元素JSON路徑?我已經試過$.store.book[?(@.price && @.category && @.title)]但這不起作用(似乎這種謂詞不允許多個條件)。有任何想法嗎?這裏是一個方便的測試儀的鏈接:https://jsonpath.curiousconcept.com/

+1

的路徑實際上是工作正常的[JsonPath] Java移植(https://github.com/ jayway/JsonPath)。 '&&'和'||'運算符僅在Java端口中可用;在線測試人員使用不同的實現。 – approxiblue

回答

0

我無法想出一個方法來做到這一點與內聯過濾器。然而,這是可能的一個過濾器對象做到這一點:

Filter f = filter(where("price").exists(true).and(where("category").exists(true).and(where("titles").exists(true)); 

致電時讀:JsonPath.read(json, "$.store.book[?]", f);