简体   繁体   中英

Jayway JsonPath Filter expression for inner array

I have a JSON file in the format below.

{  
   "queryResponse":[  
      {  
         "id":"1",
         "name":"Parent1",
         "childList":[  
            {  
               "id":"11",
               "type":"A"
            },
            {  
               "id":"12",
               "type":"B"
            }
         ]
      },
      {  
         "id":"2",
         "name":"Parent2",
         "childList":[  
            {  
               "id":"21",
               "type":"B"
            },
            {  
               "id":"22",
               "type":"C"
            }
         ]
      }
   ]
}

Using jayway JsonPath, how do I get all the Parent nodes which have child nodes with type "B"?

These filter expressions returned an empty array:

  • a wild card in the index like $.queryResponse[?(@.childList[*].type=='B')]
  • a deep scan operator in the filter field like $.queryResponse[?(@.childList..type=='B')]

The only filter expression that is closest to what I want is the one with array index for ex: $.queryResponse[?(@.childList[0].type=='A')]

Use contains or in operator

$.queryResponse[?(@.childList[*].type contains 'B')]

OR

$.queryResponse[?('B' in @.childList[*].type )]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM