组合jsonpath查询以返回筛选数组的第一个对象时出现问题

组合jsonpath查询以返回筛选数组的第一个对象时出现问题,jsonpath,Jsonpath,使用、和以下JSON: { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh",

使用、和以下JSON:

{ "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": "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
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}
我想编写一个过滤类别的查询,例如“虚构”,然后只返回第一个元素。我似乎不太明白

例如,
$…book[?(@.category==“fiction”)]
将返回一个包含3本书的数组,但我只想要第一本书:

{ "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      }

能做到吗??最明显的事情似乎是在末尾添加一个“[0]”,但它不起作用。

我检查了分析网站(注意:这是测试结果):

查找[0]索引确实有效。站点只接受jsonPath参数(jsonObj,查询字符串)中的内容,因此索引引用必须超出此评估范围,而站点不会这样做

jsonPath(foo, '$..book[?(@.category == "fiction")]')[0]

谢谢,但这不是我想要的-jsonPath返回一个数组,[0]访问数组的第一个元素。我需要jsonPath来过滤一个元素。我无法直接访问阵列。