有没有一种方法可以使用JSONPath的单个查询来获取父属性以及嵌套的子属性

时间:2019-10-20 18:33:31

标签: java jsonpath

给出以下json,

{
"store": {
    "book": [
        {
            "category": "reference",
            "sub" : {"notRequired": "value1", "required": "value2"}
            "author": "Nigel Rees",
            "title": "Sayings of the Century",
            "price": 8.95
        },
        {
            "category": "fiction",
            "sub" : {"notRequired": "value1", "required": "value2"}
            "author": "Evelyn Waugh",
            "title": "Sword of Honour",
            "price": 12.99
        }]
    }
}

预期输出为:

[
   {
      "category" : "reference",
      "sub" : {"required": "value2"}
   },
   {
      "category" : "fiction",
      "sub" : {"required": "value2"}
   }
]

我尝试了以下变化: $.store.book[*]['category', 'sub']给出了sub$.store.book[*]['category', 'sub.required']的所有属性,这些属性与任何嵌套的必需属性都不匹配。

0 个答案:

没有答案