6

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')]

rush
  • 61
  • 2

1 Answers1

0

Use contains or in operator

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

OR

$.queryResponse[?('B' in @.childList[*].type )]
Akshay G
  • 2,070
  • 1
  • 15
  • 33